15fae38b39
* Narrow type variables with union constraints when merited by contextual type * Narrow generics with union type constraints as indicated by contextual type * Accept new baselines * Add tests * Fix circularity for JSX elements * Remove unnecessary isConstraintPosition information from flow cache key * Update comment * Add additional tests * Rename to getNarrowableTypeForReference, remove getConstraintForLocation * Add comment * Fix removal of undefined in destructurings with initializers * Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers * In obj[x], use constraint of obj's type only when x's type is non-generic * Add comment
25 lines
734 B
Plaintext
25 lines
734 B
Plaintext
=== tests/cases/compiler/deeplyNestedConstraints.ts ===
|
|
// Repro from #41931
|
|
|
|
type Enum = Record<string, string | number>;
|
|
>Enum : Enum
|
|
|
|
type TypeMap<E extends Enum> = { [key in E[keyof E]]: number | boolean | string | number[] };
|
|
>TypeMap : TypeMap<E>
|
|
|
|
class BufferPool<E extends Enum, M extends TypeMap<E>> {
|
|
>BufferPool : BufferPool<E, M>
|
|
|
|
setArray2<K extends E[keyof E]>(_: K, array: Extract<M[K], ArrayLike<any>>) {
|
|
>setArray2 : <K extends E[keyof E]>(_: K, array: Extract<M[K], ArrayLike<any>>) => void
|
|
>_ : K
|
|
>array : Extract<M[K], ArrayLike<any>>
|
|
|
|
array.length; // Requires exploration of >5 levels of constraints
|
|
>array.length : number
|
|
>array : string | number[]
|
|
>length : number
|
|
}
|
|
}
|
|
|