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
functionfoo(): unknownfunctionfoo(args: string): unknownfunctionfoo(args?: string): unknown{returnargs;}declareconstarr: string[];foo(...arr);// ts compilation error here as expected π€οΈ
Two
Background
functiongetNames(){return['foo','bar','foo'];}constuniqueNames=[...newSet(...getNames())];// I mistakenly spreading the `getNames()`console.log(uniqueNames)// [ 'f', 'o' ]
Once I've wrote code above. What I expect is [ 'foo', 'bar' ]. It's really hard to find out the problem in long-line codes, if TS not reports it in compilation time.
The text was updated successfully, but these errors were encountered:
The behavior we actually work hard to exhibit here is that a spread is valid if all its possible arities result in valid calls, [...]
I think your additional "One" does not work because overloads are not supported for this case.
And the "Two" version works unfortunately due to #52060 / #9726.
π Search Terms
spreading array function parameter
π Version & Regression Information
β― Playground Link
No response
π» Code
π Actual behavior
No compilation error.
π Expected behavior
TS compilation error when calling
foo(...arr)
Additional information about the issue
One
Two
Background
Once I've wrote code above. What I expect is
[ 'foo', 'bar' ]
. It's really hard to find out the problem in long-line codes, if TS not reports it in compilation time.The text was updated successfully, but these errors were encountered: