-
Couldn't load subscription status.
- Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
Reproduced in 4.2.3 and later in playground
interface Interface {
stringOrNumber(x: string | number): void;
}
class MyClass implements Interface {
stringOrNumber(x: number) { // missing string!!!
console.log(x.toFixed(2)); // BOOM
}
}
function callInterfaceMethod(cc: Interface) {
cc.stringOrNumber("foo");
}
callInterfaceMethod(new MyClass());
var t: (x: string | number)=> void = (x: number) => { // missing string!!! error!!!
console.log(x.toFixed(2)); // BOOM
}{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "ES2017",
"jsx": "react",
"module": "ESNext",
"moduleResolution": "node"
}
}Playground Link: Provided
🙁 Actual behavior
Available implement interface with different parameters for union type
interface Interface {
stringOrNumber(x: string | number): void;
}
class MyClass implements Interface {
stringOrNumber(x: number) { // missing string!!! but no error
console.log(x.toFixed(2)); // BOOM
}
}No Error for this code.
🙂 Expected behavior
Expected type error, like in same case for simple functions
var t: (x: string | number)=> void = (x: number) => { // missing string!!! type error!!!
console.log(x.toFixed(2)); // BOOM
}Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug