-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TS3.6/3.7 regression: template arguments used in unions no longer resolve/narrow #34754
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
Comments
I presume this is an intentional change (?) but I could find an existing issue. |
IMO the inferred type is the only logical one here. You pass a variable of type |
@AlCalzone note the |
I think this is a bug; |
If there's no way to infer |
The core issue here is what, if anything, to infer for
In 3.5 we'd pick option 3 for a non-union type |
Maybe, but if this is really the benchmark: doesn't the same thing already happen any time you infer from a source |
Yes, but there's no reason an inference from |
I see what you're saying, but from a type-theoretical standpoint I view it as the same kind of question as "Given an empty array |
In the Closure compiler we would arrive at the same inference at TS3.7 (`string|undefined') which I believe to be the correct one. Effectively the question being asked is "what should As a human, in this case, you probably imagine some kind of "type subtraction" where first we remove the common elements of the argument and parameter unions, before inferring |
I point back to my empty array example: Given an empty array, what is the |
When someone writes |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.7.1-rc
Search Terms: template argument union
Code
Expected behavior:
I'd argue
string
, at least that's what the user intended here.Actual behavior:
In TypeScript version:
typeof x === string
typeof x === unknown
typeof x === string|undefined
Playground Link: n/a
The text was updated successfully, but these errors were encountered: