sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.41k stars 547 forks source link

ArraySlice: wrong type for union of tuples #982

Closed eranhirsch closed 10 hours ago

eranhirsch commented 1 week ago

Bug description

When Start is 0 and no End is provided the output should be identical to the input, but for a union of tuples this doesn't work when they are of different lengths:

type X = ArraySlice<['a'] | ['b', 'c'], 0>;
//   ^? type X = ['a' | 'b'];

This doesn't repro when Start is not provided or provided as never:

type X = ArraySlice<['a'] | ['b', 'c']>;
//   ^? type X = ['a'] | ['b', 'c'];

type Y = ArraySlice<['a'] | ['b', 'c'], never>;
//   ^? type Y = ['a'] | ['b', 'c'];

Repro

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBDAnmApnA3nAglKBDRAZQBtgBjNAXzgDMoIQ4AiJVAWhpQGcYmBuALAAoYazQANAIxwAvNlwES5FAB4A2gHI8GgLpwAPnE0AjDQBo4GsrosAGAHyChAemdx3APQD8w0cgkATLLy+ESkFOpaugZGGqYWVrqOwq7ucN6+QmJw4gDMwTihShGa2nqGJuaW1joWAHYoAG4oUMkubp4+It1AA

Upvote & Fund

Fund with Polar