Skip to content

Better Inference for mapped array and tuple types #50046

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

graphemecluster
Copy link
Contributor

@graphemecluster graphemecluster commented Jul 25, 2022

This is my attempt to fix #29841.

The checker now checks if a mapped type is an interface that extends an array or tuple, and if it is, only the elements of it are mapped and other non-array-prototype properties are discarded, behaving like the ES map method.

It also fixes Mapper<[number, ...string[], number]> being incorrectly mapped to [Mapper<number>, ...Mapper<string | number>[], Mapper<string | number>] instead of [Mapper<number>, ...Mapper<string>[], Mapper<number>], and [0, ...1[], 2] instead of [0, ...number[], number] when type Mapper<T> = { [P in keyof T]: P }.

I am new to the checker and the src code in general, so please, guide and correct me for anything weird.

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jul 25, 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
Status: Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

Improve typings of Array.map when called on tuples
3 participants