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
Weird interaction between default arguments and strict-null #11424
functionx(y='a',z: number){}functionx1(y: string,z: number){}// Construct error messages to reveal the type of these functions:lettest1: void=x;lettest2: void=x1;// They have the same type:// ERROR: Type '(y: string, z: number) => void' is not assignable to type 'void'.// ERROR: Type '(y: string, z: number) => void' is not assignable to type 'void'.// However, they have different observable behaviors:x(undefined,1);// OKx1(undefined,1);// ERROR// ERROR: Argument of type 'undefined' is not assignable to parameter of type 'string'.
Note that the second parameter (z) is necessary to trigger this behavior; if you drop z from this example, then the first param x has a ? as you'd expect.
(So it's even possible this is just a bug in how the function type is printed...?)
Activity
RyanCavanaugh commentedon Oct 6, 2016
We should be displaying the defaulted parameter as
x?or: string | undefinedsandersn commentedon Dec 8, 2016
This is a duplicate of #11900 that points out a different symptom of the bug that needs to be fixed.