TypeScript · Senior · Question 21 of 75

Can you pass a readonly string[] to a function that accepts string[]?

Explanation

The reverse direction (string[] → readonly string[]) is allowed. So parameters that the function doesn't modify are better declared as readonly T[] - then it can be called with both mutable and readonly arrays.

Further reading

Problem with a question

TypeScript · Senior · question 21

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