-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Open
Labels
Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happensSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Bug Report
π Search Terms
tuple, intersection, array, unrelated, narrowing, index signature
π Version & Regression Information
This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
/* unrelated array */
type ShouldBeNever = string[] & [1, 2, 3]
type OK = (ShouldBeNever)[number] // never
type NotOK = (ShouldBeNever)[1] // 2
type WeirdOverload = (ShouldBeNever)['pop'] // {
// (): string | undefined
// (): 3 | 1 | 2 | undefined
//}
const isString = ([1, 2, 3] as ShouldBeNever).pop() // string | undefined
/* related array but not a supertype */
type ShouldBeNarrowed = [number | string, number | boolean] & (string | boolean | symbol)[]
type FF = ShouldBeNarrowed[number] // string | boolean
type HH = ShouldBeNarrowed[0] // string | numberπ Actual behavior
The index signature is appropriately updated, but not the individual elements nor the methods operating on the resulting tuple. Additionally, methods get overloaded, so when calling pop for example, the first overload is selected and the return type is not the intersection of the original components return types as it should be.
π Expected behavior
I would expect ShouldBeNever to be [never, never, never] and ShouldBeNarrowed to be [string, boolean]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happensSuggestionAn idea for TypeScriptAn idea for TypeScript