Closed
Description
TypeScript Version: 2.8.1
Search Terms: Strict tuple, stricter tuples, tuple type narrowing, tuple union type, conditional tuple
Code
type x = [string]
type y = [string, number]
type z = x | y
function f(arg: z) {
if (arg[1] !== undefined) {
const result = arg // z; should be y
const first = result[1] // string | number; should be number
return first
} else {
return undefined
}
}
Expected behavior:
I would expect the type system to narrow the types based on unions of tuples.
Actual behavior:
Doesn't happen.
Playground Link:
Related Issues: