-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apparently, some TS changes make some code irrelevant? #31
Comments
Also mentioned this in #1 |
In my original blog post, this:
and the entire addendum are both about an issue with generic type parameters extending union types not being narrowed. So if you had |
Specifically I believe this code:
can be simplified to just use |
I'm happy to fix it, or you could if you want your name more on the codebase I will assume that what you choose here will be your general preference |
Hi, I cloned the repo and tried making the changes I talked about but it looks like the bug still exists in this instance. I'll try commenting in my original SO question and on the "closed" issue. I did make some changes in the file and the tests are still passing so I'll create a PR. I did run into a problem running all of the test script since it uses |
here is my question on the closed issue |
This is surprising. Where does it do so? I will try to be more portable. I'm also on a Windows machine, but I use git bash, so this hasn't impacted me |
Just for reference (probably belongs in a different place, here is my original SO question that lead to this whole thing. |
I ran |
oh for those are debugging stubs from when i was struggling to sort out a timing problem in CI fixing 😅 sorry |
fixed in 0.14.1 |
The changes ended up just being some type aliases, I did not make the changes I thought I could do because it looks like the issue with "type variable extending union type is not narrowed" still persists. I believe there is a way to rewrite to simplify the code, I just haven't figured it out yet. |
I think I got it! The answer here lies in making the implementation simpler, while delegating the 'type-correctness' to overloaded function declarations, so everything is inferred correctly while the implementation stays simple. Hopefully I can get a PR online tonight ( = in a few hours). function typeGuard<T extends Constructor>(o: unknown, className: T): o is ConstructedType<T>;
function typeGuard<T extends keyof typeMap>(o: unknown, className: T): o is typeMap[T];
// finally, guard ALL the types!
function typeGuard(o: unknown, className: PrimitiveOrConstructor) {
if (isPrimitiveName(className)) {
return typeof o === className;
}
return o instanceof className;
}
function isPrimitiveName(className: PrimitiveOrConstructor): className is keyof typeMap {
return (typeof className === 'string')
} |
Merjt. Following f09e77a, does this now feel open or closed to you? |
Closed, yeah.
…On Wed, Jul 28, 2021, 22:38 John Haugeland ***@***.***> wrote:
Merjt.
Following f09e77a
<f09e77a>,
does this now feel open or closed to you?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#31 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEUXSXNDX2WLCPPMMONGYALT2BMDNANCNFSM5A62C63Q>
.
|
Fixed in f09e77a |
In #5, @Krumpet said
I would like to learn more
The text was updated successfully, but these errors were encountered: