-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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
:
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
}
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug