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

fix(26058): add MergeTuple for Object.assign's return type #45731

Closed
wants to merge 2 commits into from

Conversation

hyden-tan
Copy link

@hyden-tan hyden-tan commented Sep 5, 2021

Add MergeTuple type, it support convert tuple to intersection. So, Object.assign can use it to define return type better.

/**
* Return a empty object type if the param's type is undefined
*/
type Undefined2Object<T> = T extends undefined ? {} : T;

/**
* Remove the first two item of tuple
*/
type RemoveFirstTwo<T extends unknown[], First, Second> =  T extends [a: First, b: Second, ...rest: infer P] ? P : [];

/**
* Convert tuple to intersection with tuple item's type
*/
type MergeTuple<T extends unknown[]> = T[2] extends undefined
  ? Undefined2Object<T[0]> & Undefined2Object<T[1]>
  : MergeTuple<[T[0], T[1]]> & MergeTuple<RemoveFirstTwo<T, T[0], T[1]>>;

Fixes #
#26058

Add Tuple2Intersection type, it support convert tuple to intersection. So, Object.assign can use it to define return type better.
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 5, 2021
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@ghost
Copy link

ghost commented Sep 5, 2021

CLA assistant check
All CLA requirements met.

@hyden-tan hyden-tan changed the title Update Object.assign to support unlimited params Add Tuple2Intersection type for Object.assign's return type Sep 6, 2021
@hyden-tan hyden-tan changed the title Add Tuple2Intersection type for Object.assign's return type fix(#26058): add Tuple2Intersection for Object.assign's return type Sep 6, 2021
@hyden-tan hyden-tan changed the title fix(#26058): add Tuple2Intersection for Object.assign's return type fix(26058): add Tuple2Intersection for Object.assign's return type Sep 6, 2021
@hyden-tan hyden-tan changed the title fix(26058): add Tuple2Intersection for Object.assign's return type fix(26058): add MergeTuple for Object.assign's return type Sep 6, 2021
@hyden-tan hyden-tan closed this Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants