-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
type parameter constraint
π Version & Regression Information
- This changed between versions 4.9.0-dev.20220914 and 4.9.0-dev.20220915
β― Playground Link
Playground link with relevant code
π» Code
export type TypeA = {
A: 'A',
B: 'B',
}
export type TypeB = {
A: 'A',
B: 'B',
C: 'C',
}
// Fails to index TypeA with T
type R<T extends keyof TypeA> =
T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never
// This one works
type R2<T extends PropertyKey> =
T extends keyof TypeA ?
T extends keyof TypeB ?
[TypeA[T], TypeB[T]] : never: neverπ Actual behavior
In R, TypeA[T] causes an error: Type 'T' cannot be used to index type 'TypeA'.
π Expected behavior
TypeA[T] should work since T is by definition constrained to be a keyof TypeA
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue