Closed
Description
TypeScript Version: 2.4.1
Code
function f(callback: (a: string, b?: string) => void) {
callback("a", undefined);
}
f((a: string, b: string) => {
console.log(a.length, b.length);
});
Expected behavior:
Compile error with when compiled with the strict
flag.
(a: string, b: string) => void
is not a subtype of (a: string, b?: string) => void
as string
is not a supertype of string | undefined
, I expected a compile error.
Actual behavior:
Compiles, but throws error at runtime
console.log(a.length, b.length);
^
TypeError: Cannot read property 'length' of undefined
at /Users/Ali/test.js:11:28
at f (/Users/Ali/test.js:3:5)
at Object.<anonymous> (/Users/Ali/test.js:10:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)