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
Generic function with rest parameters does not infer or widen actual args to union type #37673
// A *self-contained* demonstration of the problem follows...functionfoo<Textendsstring|number>(...rest: T[]): T[]{returnrest;}foo('a',1);
Expected behavior:
Should compile without error and infer the return type of foo('a', 1) to be at least (string | number)[] or, better still, more accurately as ("a" | 1)[]
Actual behavior:
src/main.ts:5:10 - error TS2345: Argument of type '1' is not assignable to parameter of type '"a"'.
5 foo('a', 1);
Related Issues:
Looked at #37052 for a clue. The only thing there was a similar error message to mine above but otherwise probably a red herring to say that it's similar.
Activity
RyanCavanaugh commentedon Apr 1, 2020
This is consistent with the non-rest version:
typescript-bot commentedon Apr 3, 2020
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.