-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: Version 2.0.5
Code
(with --strictNullChecks on)
function x(y = 'a', z: number) {}
function x1(y: string, z: number) {}
// Construct error messages to reveal the type of these functions:
let test1: void = x;
let test2: 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); // OK
x1(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...?)
svieira
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue