-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Narrowing breaking changes #7662
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
In the first example |
narrowing makes the type more "specific", this seems like expanding the domain of the type. |
I thought that "more specific than" means "subtype of". That would mean that narrowed types are always a subtype of their original type and also always assignable to the original type. |
Type parameter narrowing is tracked by #8563 |
Can typescript track that variable isn't changed after bypassing to callback and keep that narrow inside callback? {
let aOrB: A|B = getAOrB()
if (isA(aOrB)) {
performOperationA(() => aOrB /* is A here */)
} else {
performOperationB(() => aOrB /* is B here */)
}
// there is no write-aware operations on aOrB after this point,
// seems that typescript may be able to catch this case and keep var narrow inside callbacks.
} |
it can be done, but that is not trivial amount of computing, and would impact compilation times for all projects. |
@Strate In that case you can yourself use |
This is a place holder for changes to the type narrowing behavior in TypeScript 2.0:
See the explanation by @Arnavion in #7719 (comment)
The text was updated successfully, but these errors were encountered: