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
Search Terms:
Union array type element inference in methods Code
typeUnpack<T>=TextendsReadonlyArray<infer P> ? P : never;consttest: ['a','b']|['c','d']=['a','b']asany;test.forEach(el=>el);//error: Parameter 'el' implicitly has an 'any' typetest.forEach((el: Unpack<typeoftest>)=>el);constelement=test[1];
Expected behavior:
Both forEach calls should infer col in the same way: el should be 'a' | 'b' | 'c' | 'd' Actual behavior:
First call can't infer el type.
TypeScript Version: 4.1.0-dev.20200903
Search Terms:
Union array type element inference in methods
Code
Expected behavior:
Both
forEach
calls should infer col in the same way: el should be 'a' | 'b' | 'c' | 'd'Actual behavior:
First call can't infer el type.
Playground Link:
https://www.typescriptlang.org/play?ts=4.1.0-dev.20200903#code/C4TwDgpgBAqgdmAhgYwNYB4AqA+KBeKTKCAD2AjgBMBnKAJQkUoHs4AbEAQQCdvER0ASzgAzCNygAFXAH4pUAFxQ4EAG7iA3ACgtyVtWBRyBpQG0A5InMAaKOYBG5gLpQAPlAvIbdys-wfLbwc-RFpEOBBtLWNgADoRZm4AURQACwAKCDZ8XCyASm0Y+MSU5AzMtiV4JDR0UEhmESMIA2w8nOI2At19QyyIAFsKQwIY0wBGJw0gA
Related Issues:
The text was updated successfully, but these errors were encountered: