TypeScript · Senior · Question 2 of 75

Why doesn't strictFunctionTypes apply to a method declared as handle(x: Dog): void?

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.

Further reading

Problem with a question

TypeScript · Senior · question 2

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz