TypeScript · Senior · Question 2 of 75
Why doesn't strictFunctionTypes apply to a method declared as handle(x: Dog): void?
- ✓Correct answer: Method-syntax parameters are checked bivariantly for compatibility
- 2Class and interface methods aren't checked for compatibility at all
- 3The flag applies only to arrow functions declared in classes
Explanation
Method bivariance was kept so that many built-in types (e.g. Array<T>) stay compatible. If you declare a function property handle: (x: Dog) => void instead, the check is strict. That's why property syntax is often preferred for callbacks in interfaces.