-
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
Type guard for child not transitive parent object #58241
Comments
Duplicate of #42384. Due to various design limitations, type narrowings of object properties currently don't propagate to the containing object except for the special case of discriminated unions. |
Yes, it is duplicated, I'm not sure it should be discussed here and #42384 .
If I read correctly, it is due to performance issue so we choose not to implement this? I dived into source code and const type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode); I think the performance issue is refer to here we won't like to generate a new type every time we Correct me I'm wrong In current design when checking if
I see now |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
"is not assignable", "ts(2345)"
🕗 Version & Regression Information
[Type System Behavior](https://github.com/Microsoft/TypeScript/wiki/FAQ#type-system-behavior)
⏯ Playground Link
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoQM5mQbwFDLJgCeADhAFzIBEc1yAPjQEbUDcByCAFsADYATKBBBUQAVwC2zaAG0Auo2QTp0DgF88JcmkxgAglChxiyALzIA8pOBgAPOiwAaGj35CR1AHzIAZLk43QWFRZSkZKAUNDm0URzAAZTAoUABzc10sPwDCWKpadjx1DjwEAHsQLJgARgyACgB9KnjDY2IASnMfHGLSiqqAJnqmzMTktM6zbt68OrhmvUnuzmAYZDrWkwA6YAxN4jmtoI8Qds78QkJyyrK+CC2+MtTD45CHkVSwbnaOS+QauY-TiaQirdZwLaxcxmCwFc6cQgwAaA37ITS9IA
💻 Code
🙁 Actual behavior
Complain with error
🙂 Expected behavior
Pass the type check, since we already checked
a.children
, actually compiler knows typeofa.children
isnumber[]
here, why it forget this when we treata
as a whole?Additional information about the issue
I know we could have a user defined type guards like this
The text was updated successfully, but these errors were encountered: