Closed
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