We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
TypeScript Version: 4.3.0-dev.20210315
Search Terms: array isArray readonly
The first problem is that Array.isArray lets us violate readonly modifier and push values to ReadonlyArray:
Array.isArray
readonly
ReadonlyArray
declare const data: ReadonlyArray<any> if (Array.isArray(data)) { // Expected: Error data.push(123) }
The second problem is that Array.isArray doesn't filter out ReadonlyArray type:
declare const data: Record<string, any> | ReadonlyArray<any> if (!Array.isArray(data)) { // now: readonly any[] | Record<string, any> // expected: Record<string, any> const alias = data }
TypeScript Version: 4.3.0-dev.20210315
Search Terms: array isArray readonly
The first problem is that
Array.isArraylets us violatereadonlymodifier and push values toReadonlyArray:The second problem is that
Array.isArraydoesn't filter outReadonlyArraytype: