-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Different behavior for {} and unknown narrowed to {} #50531
Comments
I'm guessing what happens is that once I think there's an internal distinction between regular |
For the record, the narrowing of |
|
Case in point: Primitives can also be assigned to For the narrowing to |
Oh, I see what you mean. I didn’t realize that |
Yeah, every once in a while someone opens an issue about |
Oh, maybe the narrowing of |
This was my hypothesis as well. |
Bug Report
I found a curious situation in Typescript 4.8 where a variable of type
unknown
narrowed down to{}
behaves differently than a variable of type{}
from the beginning.🔎 Search Terms
4.8, narrow, in
Not sure if it is related to #50527.
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Narrowing
unknown
to{}
and then using thein
operator results in an incorrect type, whereas it doesn’t happen when starting with a variable of type{}
.🙂 Expected behavior
Narrowing should behave the same way whether we start with the type
{}
or narrowunknown
down to{}
.The text was updated successfully, but these errors were encountered: