Skip to content

Compute dervied generic-ness for substitutions and create lower priority inferences for substitutes #43765

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

Merged

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Apr 21, 2021

Fixes #43591

We're been making non-generic substitutions for quite awhile now, but haven't handled them appropriately in isGenericObjectType or isGenericIndexType (they behave as though they're generic, hence the unexecuted conditional in the linked issue). With that in place, the linked issue further makes it obvious that these substitutions can create unwanted inference results - Array<number> extends Array<infer T> should clearly infer number for T, but naively does not in this context, because Array<number> actually substitutes to Array<number> & Array<any>, which in turn taints the result. By making an inference from the base type of the substitute first, and then a lower priority inference from the full substitute, we can preferentially pull the result from the original, un-substituted type where possible (thus allowing the result from the linked issue to be the expected number).

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 21, 2021
@weswigham weswigham merged commit dee4903 into microsoft:master Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team 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.

Conditional type partially computed
4 participants