You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an effect of #30637. Previously, unconstrained type parameters were treated as if they had the constraint {} and therefore could never be null or undefined. That isn't correct because an unconstrained T can be instantiated at any type, including null or undefined. In 3.5 we now check it correctly. That specifically means that bar !== undefined doesn't imply that T disappears from the type in the false branch.
If you explicitly add a constraint to T you get the expected behavior:
thank you for clarification @ahejlsberg, should have read the changelog more carefully.
The new constraint is a bit more verbose, but makes sense to me logically.
Closing the issue!
TypeScript Version: 3.5.0-rc / next
Search Terms: 3.5, 3.5 union, 3.5 strict
Code
test.ts:
CLI:
Expected behavior:
Compiles and behaves like ts 3.4.5
Actual behavior:
Error:
Related Issues:
Cannot judge, if it is a duplicate of #31380 .
This is some specific case to base further evaluation on.
The text was updated successfully, but these errors were encountered: