Skip to content
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

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Apr 6, 2022

related to #48538
closes #45255

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Apr 6, 2022
@typescript-bot
Copy link
Collaborator

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.

Comment on lines +95 to +101
test({
a: () => 0,
b: (a) => a,
c: (b) => {
const x: number = b;
}
});
Copy link
Contributor Author

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 R1and 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 😉

Comment on lines +190 to +201
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
}
})
Copy link
Contributor Author

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'

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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!

@DanielRosenwasser DanielRosenwasser merged commit 702bc52 into microsoft:main Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Probable bug: Can't infer an invariant generic on contravariant position when involving another generic
3 participants