- Notifications
You must be signed in to change notification settings - Fork 13.2k
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
TypeScript Version: 4.2.0-dev.20201211
Search Terms: nested templates, extract
Code
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:
typeEnum=Record<string,string|number|any>;Then it works fine.
Playground Link:
here
Related Issues:
maybe related to #41380, if so this is a relatively simpler test case.
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