Open
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]