Skip to content

[isTypeReadonly] Intersections involving a readonly array fail #4428

@RebeccaStevens

Description

@RebeccaStevens
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

type TestTest1 = ReadonlyArray<string> & Readonly<{ foo: string; }>;
type TestTest2 = Readonly<ReadonlyArray<string>> & Readonly<{ foo: string; }>;
isTypeReadonly(checker, type, {})

Expected Result

isTypeReadonly should return true

Actual Result

isTypeReadonly returns false

Additional Info

The error seems to be that TypeScript treats Readonly<ReadonlyArray<string>> the same as ReadonlyArray<string> and thus the methods are still mutable. We need a special case to handle intersections with readonly arrays.

Versions

package version
@typescript-eslint/type-utils 5.9.0
TypeScript 4.5.4
node 17.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: type-utilsIssues related to the @typescript-eslint/type-utils package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions