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
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...?)
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: Version 2.0.5
Code
(with
--strictNullChecks
on)Note that the second parameter (
z
) is necessary to trigger this behavior; if you dropz
from this example, then the first paramx
has a?
as you'd expect.(So it's even possible this is just a bug in how the function type is printed...?)
The text was updated successfully, but these errors were encountered: