TypeScript · Junior · Question 12 of 75

How do you type a function that takes a string and returns a number?

Explanation

In a function type, parameter names are required: (s: string) => number. (string) => number means a parameter named string of type any. A function declaration: function len(s: string): number { ... }.

Further reading

Problem with a question

TypeScript · Junior · question 12

Test yourself

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

Take this quiz