Functions with intersection arguments are not always typed coherently · Issue #9514 · microsoft/TypeScript (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
TypeScript Version: 1.8.10
Code
// tl;dr: // This should give a static error, but does not. var monkeyAnalyzer: (input: Monkey) => void = (input: Monkey & Robot) => { console.log(input.FurColor, input.MotorCount); } // Will definitely fail, as we can expect from the incompatible signatures of the declared type of monkeyAnalyzer and what we actually assign to it monkeyAnalyzer(new Monkey());
// Verbose example class Monkey { public FurColor: string; }
class Robot { public MotorCount: number; }
class MonkeyRobotAnalyzer { public static Analyze = (input: Monkey & Robot): void => { console.log(input.FurColor, input.MotorCount); } }
class MonkeyManager { constructor(monkeyAnalyzer: (input: Monkey) => void) { monkeyAnalyzer(new Monkey()); } }
MonkeyRobotAnalyzer.Analyze(new Monkey()); // Shows error as it should
var myManager = new MonkeyManager(MonkeyRobotAnalyzer.Analyze); // No error, but should not be allowed, signature of MonkeyRobotAnalyzer.Analyze is not compatible with (input: Monkey) => void
Expected behavior:
The incompatible signatures should result in a static error
Actual behavior:
We get no static error