Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[isTypeReadonly] Intersections involving a readonly array fail #4428

Closed
3 tasks done
RebeccaStevens opened this issue Jan 10, 2022 · 0 comments · Fixed by #4429
Closed
3 tasks done

[isTypeReadonly] Intersections involving a readonly array fail #4428

RebeccaStevens opened this issue Jan 10, 2022 · 0 comments · Fixed by #4429
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: type-utils Issues related to the @typescript-eslint/type-utils package

Comments

@RebeccaStevens
Copy link
Contributor

RebeccaStevens commented Jan 10, 2022

  • 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
@RebeccaStevens RebeccaStevens added package: type-utils Issues related to the @typescript-eslint/type-utils package triage Waiting for maintainers to take a look labels Jan 10, 2022
@RebeccaStevens RebeccaStevens changed the title [isTypeReadonly] Intersection of array with record fails [isTypeReadonly] Intersections involving a readonly array fail Jan 10, 2022
RebeccaStevens added a commit to RebeccaStevens/typescript-eslint that referenced this issue Jan 10, 2022
RebeccaStevens added a commit to RebeccaStevens/typescript-eslint that referenced this issue Jan 10, 2022
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working and removed triage Waiting for maintainers to take a look labels Jan 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: type-utils Issues related to the @typescript-eslint/type-utils package
Projects
None yet
2 participants