TypeScript | Generics in TypeScript | Question10

Last Updated :
Discuss
Comments

Which of the following is a correct use of the ReadonlyArray<T> built-in generic type?

TypeScript
function printNumbers(numbers: ReadonlyArray<number>): void {
    numbers.forEach((num) => console.log(num));
    // numbers.push(10); // Error
}


It ensures the array numbers cannot be modified.

It allows adding new elements to numbers.

It is identical to a regular array.

It throws an error at runtime if numbers is modified.

Share your thoughts in the comments