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
{{ message }}
Repository navigation
Template literals not widening to a union type when spread as function parameters #46768
When provided with certain template literal types, array generics do not widen to a union array type when spread as function parameters, but does work correctly if not spread.
Reproduced on v4.5.0-beta, v4.4.4 and v4.3.5. Prior to v4.3, there was another bug with template literals that may occlude this one, so hard to say if it's a regression or just inherent to how template literals were written initially.
typeDotString= `${string}.${string}.${string}`;functionnoSpread<PextendsDotString>(args: P[]): P{returntrueasany;}functionspread<PextendsDotString>(...args: P[]): P{returntrueasany;}noSpread([`1.${'2'}.3`,`1.${'2'}.4`]);// fine: "1.2.3" | "1.2.4"noSpread([`1.${'2'asstring}.3`,`1.${'2'asstring}.4`]);// fine: `1.${string}.3` | `1.${string}.4`spread(`1.${'2'}.3`,`1.${'2'}.4`);// fine: "1.2.3" | "1.2.4"spread(`1.${'2'asstring}.3`,`1.${'2'asstring}.4`);// error: Argument of type '`1.${string}.4`' is not assignable to parameter of type '`1.${string}.3`'.(2345)
🙁 Actual vs. Expected behavior
The second call to spread() should have the same return type as the second call to noSpread(), but there is an error on the second argument where the generic seems to be stuck on the narrowed first type.
Activity