-
Notifications
You must be signed in to change notification settings - Fork 69
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
Issues with type narrowing in if-else statements #28
Comments
Alright, I think I've tracked this one down. As far as I can tell, the type narrowing only works when Will you try turning on |
Here's a super simple replication in the typescript playground |
Looks like this is a known bug: microsoft/TypeScript#10564 |
@vultix. Wow, thanks this worked. Appreciate the fast response. Would it make sense to make a note of this somewhere in the docs? |
I added a note in the README. I'm going to close this issue for now, hopefully this gets fixed in Typescript soon |
Hi there!
Thanks for making this, been enjoying this library.
I am running into an issue with the type narrowing for if-else statements. I'm not sure if I'm doing something wrong, but this issue was mentioned in #5. I expect that a type guard on
result.ok
would narrow the union type appropriately in the else block. Instead I see an error like this:Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'.
Currently on typescript 4.2.4
Here are two examples that are more or less the same.
The text was updated successfully, but these errors were encountered: