Skip to content

T[K] should be never when T is never #23005

Closed
@kpdonn

Description

@kpdonn

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions