-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add additional tests for intra expression inference #48584
Conversation
The TypeScript team hasn't accepted the linked issue #45255. If you can get it accepted, this PR will have a better chance of being reviewed. |
test({ | ||
a: () => 0, | ||
b: (a) => a, | ||
c: (b) => { | ||
const x: number = b; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#45255 has 2 failing test cases, the 3rd call is basically the same as the call above this one here, but the 1st call (the one that is being added here) is slightly different - it "transfers" the return type from a
to the c
parameter type through the identity b
. So it computes R1
and R2
to be the same.
Perhaps it's not that different from the other test case but maybe it's worth adding - i will let you be the judge of that 😉
declare const branch: | ||
<T, U extends T>(_: { test: T, if: (t: T) => t is U, then: (u: U) => void }) => void | ||
|
||
declare const x: "a" | "b" | ||
|
||
branch({ | ||
test: x, | ||
if: (t): t is "a" => t === "a", | ||
then: u => { | ||
let test1: "a" = u | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very similar to some other cases here but this has an interesting return type annotation at if
. Previously u
in then
was inferred to be of type 'a' | 'b'
but now it gets correctly narrowed down to 'a'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem like interesting test-cases. Thanks!
related to #48538
closes #45255