Closed
Description
TypeScript Version: 2.9.0-dev.20180329
Search Terms:
indexed access type, index type never
Code
type Example<T extends Record<'a', string>> = T['a']
type Result1 = Example<{ a: "x" } | { a: "y" }> // type of Result1 is "x" | "y"
type Result2 = Example<{ a: "x" }> // type of Result2 is "x"
type Result3 = Example<never> // type of Result3 is any
Expected behavior:
Type of Result3
to be never
Actual behavior:
Type of Result3
is any
Playground Link:
Link
Workaround
Now that #22042 is resolved this can be worked around with
type Workaround<T extends Record<'a', string>> = T[(keyof T) & 'a']
type Result4 = Workaround<never> // type of Result4 is never in typescript@next
Related Issues:
Similar to #22042. That was about type of T[K]
when K
was never
while this is about when T
is never
.