Revert return type narrowing - #61136
Conversation
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Gabriela Araujo Britto (@gabritto), the results of running the DT tests are ready. Everything looks the same! |
|
Gabriela Araujo Britto (@gabritto) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Gabriela Araujo Britto (@gabritto) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Gabriela Araujo Britto (@gabritto) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Jake Bailey (jakebailey)
left a comment
There was a problem hiding this comment.
😢
Should we keep the tests behind for the future, rather than deleting them?
I'll just revert this PR when I re-introduce narrowing for 5.9, so it will have the deleted tests again. |
This reverts commit c3ae7c4.
As discussed in design meeting on Feb 4th, the current design for return type narrowing doesn't work well with object types, and that aspect needs to be fixed before the feature can be released.
My notes on the problem are here: https://gist.github.com/gabritto/b6ebd5f9fc2bb3cfc305027609e66bca
This PR reverts return type narrowing, but keeps the change where we check each branch of a conditional return expression separately, since that change, although a breaking one, uncovered bugs in vscode and Google.
My plan is to later fix return type narrowing and get the fixed version in TS again for the 5.9. The planned fix is to restrict return type narrowing for cases where we the function/return type distinguishes between primitive types or primitive and object types, e.g. cases where the parameter has type
string | numberorstring | string[]. These are the cases where regular type narrowing already works well, and avoids the problems mentioned in the notes. Then, on top of that restriction, we'll enable embedding the "narrowable" type parameter in an object type (see https://gist.github.com/gabritto/b6ebd5f9fc2bb3cfc305027609e66bca#alternative-2-embedding).