• Courses
  • Tutorials
  • Practice
  • Contests
Switch to Dark Mode

TypeScript | Generics in TypeScript | Question10

Last Updated : Mar 22, 2025
Discuss
Comments

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

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


A

It ensures the array numbers cannot be modified.

B

It allows adding new elements to numbers.

C

It is identical to a regular array.

D

It throws an error at runtime if numbers is modified.

Share your thoughts in the comments