-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Generic lookup type wrongly narrowed to never
with strictNullChecks
#26130
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
This is just weird. Writing const x = element!.x; eliminates the error, but there shouldn't be anything for |
Not a regression FWIW |
FWIW |
I found the problem: in Using the comparable relation in place of |
typeMaybeAssignableTo. typeMaybeAssignableTo decomposed unions at the top level of the assigned type but didn't properly handle other unions that arose during assignability checking, e.g., in the constraint of a generic lookup type. Fixes microsoft#26130.
Proposed fix is in #26143. |
types. Fixes microsoft#26405. Also add a debug assert to catch any future cases like microsoft#26130 in which the target type of a valid assignment is narrowed to something to which the source type is no longer assignable.
…microsoft#26130 by skipping narrowing if the old algorithm produces a type to which the assigned type is not assignable. This also means we'll no longer narrow for erroneous assignments where the assigned type is not assignable to the declared type. This is the reason for the numericLiteralTypes3 baseline change. Fixes microsoft#26405.
Go back to old narrowing algorithm but don't narrow in cases like #26130
I ran across this while migrating my project to
strictNullChecks
and it's positively bizarre.TypeScript Version: master (50f442f)
Search Terms: mapped type narrow narrowing null strictNullChecks never
Code (with
strictNullChecks
)Expected behavior: Compile without error.
Actual behavior: Error: Property 'x' does not exist on type 'never'.
Playground Link: link (remember to enable strictNullChecks)
Related Issues: Didn't find any.
The text was updated successfully, but these errors were encountered: