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
never rest type not assignable to complex rest type #33495
Interestingly, [ string, ...T ] (where T is generic but extends any[]) isn't even legal and produces the error A rest element type must be an array type. This seems like a pretty big clue: the assignment of fn1 to fn2 may only be failing because it's unable to construct a tuple type for the parameter list of (x: string, ...rest: T) => unknown.
constsourceCount=getParameterCount(source);constsourceRestType=getNonArrayRestType(source);consttargetRestType=getNonArrayRestType(target);if(sourceRestType&&targetRestType&&sourceCount!==targetCount){// We're not able to relate misaligned complex rest parametersreturnTernary.False;}
A rest type where you don't know the bounds, or whether it is unbounded---I would guess. I think never needs to be treated like any in that it is effectively known to be unbounded.
* Safer version of `Function` which should not be called.
* Every function should be assignable to this, but this should not be assignable to every function.
*/
exporttypeAnyFunction=(...args: never[])=>void;
/** * Safer version of `Function` which should not be called. * Every function should be assignable to this, but this should not be assignable to every function. */exporttypeAnyFunction=(...args: never[])=>void;functionfoo<Textendsany[]>(){constfn1: (...rest: T)=>void=(..._)=>{};constfn2: AnyFunction=fn1// error}
Activity
jack-williams commentedon Sep 18, 2019
The goal here would be to make all signatures structurally assignable to
(...args: never) => unknown.RyanCavanaugh commentedon Sep 18, 2019
Anders Hejlsberg (@ahejlsberg) this seems reasonable to me. Thoughts?
fatcerberus commentedon Sep 18, 2019
I did some experiments in the playground. This seems to break only when the rest parameter is generic. Use a concrete type and all is well:
Interestingly,
[ string, ...T ](whereTis generic but extendsany[]) isn't even legal and produces the errorA rest element type must be an array type.This seems like a pretty big clue: the assignment offn1tofn2may only be failing because it's unable to construct a tuple type for the parameter list of(x: string, ...rest: T) => unknown.jack-williams commentedon Sep 18, 2019
This is where it fails in checking:
fatcerberus commentedon Sep 18, 2019
Jack Williams (@jack-williams) That doesn't seem to explain why it succeeds for the non-generic case. What is the exact definition of "complex" here?
jack-williams commentedon Sep 18, 2019
A rest type where you don't know the bounds, or whether it is unbounded---I would guess. I think
neverneeds to be treated likeanyin that it is effectively known to be unbounded.jack-williams commentedon Sep 18, 2019
FWIW. I think the fix is basically:
+ isTypeNever.AnyhowStep commentedon Dec 1, 2019
Repro taken from TS' source code,
TypeScript/src/compiler/core.ts
Lines 1460 to 1464 in c447ebc
Playground
But not every function is assignable to it