You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeEnum=Record<string,string|number>;typeTypeMap<EextendsEnum>={[keyinE[keyofE]]: number|boolean|string|number[]};classBufferPool<EextendsEnum,MextendsTypeMap<E>>{setArray1<KextendskeyofM>(_: K,array: Extract<M[K],ArrayLike<any>>){array.length;// correct}setArray2<KextendsE[keyofE]>(_: K,array: Extract<M[K],ArrayLike<any>>){array.length;// compile-time error, which is NOT expected: 'length' does not exist on type 'Extract<M[K], ArrayLike<any>>'}}
Expected behavior:
Code compiles without error.
Actual behavior:
Compiler throws Property 'length' does not exist on type 'Extract<M[K], ArrayLike<any>>'.
Behavior starts at 4.1 I think, the exact same code works prior to that.
Note that if we change the definition on the first line to:
The test case is extracted from our main codebase, boiled down to its essence.
We got a little creative about type checking the memory pool system, and it has been incredibly helpful when using these low-level interfaces:
enumEnum1{data1,data2,data3,}interfaceTypeMap1extendsTypeMap<typeofEnum1>{[Enum1.data1]: number;[Enum1.data2]: boolean;[Enum1.data3]: number[];}constpool=newBufferPool<typeofEnum1,TypeMap1>();pool.setArray2(Enum1.data3,[3]);// correctpool.setArray2(Enum1.data2,[3]);// compile-time error, which is expected: 'number' is not assignable to parameter of type 'never'pool.setArray2(Enum1.data3,3);// compile-time error, which is expected: 'number' is not assignable to parameter of type 'number[]'
This looks to be caused by #40971. Once we get to seven nested levels of constraint exploration, the depth limiter cuts off further exploration. Here's the progression:
The issue is that all of the constraint breakdown happens in the check type of the conditional type, but all the depth limiter sees is a deep sequence of instantiations of the same conditional type.
We're probably a bit too aggressive in cutting off constraint exploration after only five levels, particularly given this fairly reasonable example. Shouldn't be too hard to increase the threshold.
TypeScript Version: 4.2.0-dev.20201211
Search Terms: nested templates, extract
Code
Expected behavior:
Code compiles without error.
Actual behavior:
Compiler throws
Property 'length' does not exist on type 'Extract<M[K], ArrayLike<any>>'.
Behavior starts at 4.1 I think, the exact same code works prior to that.
Note that if we change the definition on the first line to:
Then it works fine.
Playground Link:
here
Related Issues:
maybe related to #41380, if so this is a relatively simpler test case.
The text was updated successfully, but these errors were encountered: