TypeScript · Senior · Question 35 of 75

Why should you avoid the Function type for callbacks?

Explanation

Function describes any function, and calling it is unsafe. Prefer a precise signature (value: string) => void, and for "any function" use (...args: never[]) => unknown or (...args: any[]) => any. Likewise, Object and {} are better replaced with object or unknown.

Further reading

Problem with a question

TypeScript · Senior · question 35

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