-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
type assertions affect the type narrowing of the subsequent code #58050
Comments
This is no crash. Crash means the compiler crashes, not you receiving an error.
You probably mean 5.4.3? There is no version 5.3.4. |
Excuse my carelessness; I have made revisions. |
That's very strange. I'll take a look. |
The issue here appears to be inconsistent caching of union and intersection property lookups, specifically the caching logic in |
I see what's happening. For various reasons we have two caches for resolved property lookups on unions and intersections, one that includes property augmentations from |
π Search Terms
Type Assertion type Narrowing
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.3#code/JYWwDg9gTgLgBAbzjAnmApnAwhcEB26+MANMmpgAoA2ArgObD5wC+cAZlLnAOQButdDwBQwgPRjyGbHAC82XJELEA2j3wBDEEIC6w9AA9IsKZhx5lMAOrAYACwCS+AM4wN1agB4AKgD45cN5wAGRwNAxM+kbQ8KjSNvZOru7U4YzM8kgA+mBQ6OzABgD8AFxwrlBM9Kyihsbw7LT4AMYwwARwAO62ji5uHp5YcIYwRAAmzgoWRKSBwwaj+BNwCb3JHmlMvgAUwnBwzYoEM2VDAD7YKjoke8gaUPToMKWBwgCUZRVViLeHfQdHSyrJL9agBbZuB5POBFIoA6bEN5wDSTcxKGbAvopHy+X4EVzw9HESbyACCUCgGhQADpgM5yZSUNtDgiYEi4SyifAyipOcdiHo8f8kJptKwAnzLM4VAAGHRwW7Adhwbai9BIhC3fZ5GC0KDMNW3FiibVPPXMABEFuExuEQA
π» Code
π Actual behavior
the name property is underlined in red, indicating an error.
The
type C = Component['name']
is valid, as thename
property exists within theComponent
type. When I removeconst componentWithInstall = (target ?? component) as ComponentWithInstall<T>
, everything returns to normal. Alternatively, if I uncommenttype C = Component['name']
, even though it's not used anywhere, the error disappears. Type assertions should not affect the type narrowing of subsequent code, but an error occurs. This code worked fine in version 5.3.3, but started to error in version 5.4.3.π Expected behavior
Ts don't report the error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: