Skip to content

Bug: [prefer-readonly-parameter-types] Doesn't work on DeepReadonly from ts-essentials, utility-types, and type-fest #8932

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

Closed
4 tasks done
emily61268 opened this issue Apr 15, 2024 · 7 comments
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@emily61268
Copy link

emily61268 commented Apr 15, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.4.3&fileType=.tsx&code=JYWwDg9gTgLgBAbzgEQKarAJVQQwCYQB2ANgJ5wC%2BcAZlBCHAOQwDOAtKiy6oTMDsRaMA3AChRqAB6RYNAK6EAxnyJwW9VGhAQAYguXAiAClFw1MUsU3ADRHFFIAuFOiy4CJUgB4AyhavINiqE9qQAdADC0KgAfAA0pnAhIKjOLDBQwIQA5gkAlM4AcjgpeL4aAOJ0cmAxiIlQqDByUIRqGgDyMAAWqFB6SsEmZmYIiSNJJalwAAZ4qNoA9AAkCMmoFDMJE2bqKR0ARgBWqMpp-ta2IQ5he6hVEDUA2usAutsjFIl5Yl9AA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

export function someDemoFunction(
    styleDictionary: DeepReadonly<StyleDictionary.Core>,
    name: string,
): Named<SomeGroup> {
  return someOtherFunction(
      {
        name: `demo/${name}`,
        someObject: styleDictionary.someGroup[name],
      }
  );
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/prefer-readonly-parameter-types": [
        "error",  
        { ignoreInferredTypes: true },
    ],
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

There shouldn't be any eslint errors.

Actual Result

Returns the following error for styleDictionary: DeepReadonly<StyleDictionary.Core>.
34:3 error Parameter should be a read only type @typescript-eslint/prefer-readonly-parameter-types

Additional Info

Data types in StyleDictionary.Core: https://github.com/amzn/style-dictionary/blob/main/types/index.d.ts#L59
ts-essentials DeepReadonly: https://github.com/ts-essentials/ts-essentials/blob/master/lib/deep-readonly/index.ts
utility-types DeepReadonly: https://github.com/piotrwitek/utility-types/blob/master/src/mapped-types.ts#L407
type-fest ReadonlyDeep (recommended in this issue): https://github.com/sindresorhus/type-fest/blob/main/source/readonly-deep.d.ts

@emily61268 emily61268 added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 15, 2024
@emily61268 emily61268 changed the title Bug: [prefer-readonly-parameter-types] Doesn't work on DeepReadonly from ts-essentials and utility-types Bug: [prefer-readonly-parameter-types] Doesn't work on DeepReadonly from ts-essentials, utility-types, and type-fest Apr 15, 2024
@emily61268
Copy link
Author

Also, how do I check which in StyleDictionary.Core is not covered by DeepReadonly? Thanks.

@bradzacher
Copy link
Member

Considering this requires a number of different dependencies to reproduce - could you please create an isolated reproduction repo with the required setup to reproduce?

Either that or recreate the exact state in the playground. Note that our playground does not download dependencies so it cannot be run off imports.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Apr 16, 2024
@emily61268
Copy link
Author

emily61268 commented Apr 16, 2024

I was able to pinpoint the one data type that might have caused this error, which is RegExp in Parser[], so I decided to use the allow option that you mentioned in this issue to ignore RegExp. However, when I tried to update .eslintrc.js file to include allow config for @typescript-eslint/prefer-readonly-parameter-types, I kept getting the following error:

Oops! Something went wrong! :(

ESLint: 8.54.0

Error: .eslintrc.js#overrides[0]:
	Configuration for rule "@typescript-eslint/prefer-readonly-parameter-types" is invalid:
	Value {"allow":[{"from":"lib","name":"RegExp"}],"ignoreInferredTypes":true} should NOT have additional properties.

    at ConfigValidator.validateRuleOptions (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2039:23)
    at /Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2094:18
    at Array.forEach (<anonymous>)
    at ConfigValidator.validateRules (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2091:34)
    at ConfigValidator.validateConfigArray (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2217:18)
    at CascadingConfigArrayFactory._finalizeConfigArray (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3974:23)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3780:21)
    at FileEnumerator._iterateFilesWithFile (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
    at FileEnumerator._iterateFiles (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
    at FileEnumerator.iterateFiles (/Volumes/workplace/SamplePackage/src/SamplePackage/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)

Here's my config for ESLint: Link (Go to eslintrc tab, but the playground cannot reproduce the error I have.)
Can you please help why it doesn't work? Thank you.

@bradzacher
Copy link
Member

If you can't repro in the playground - then likely your versions don't align.
Given your error message says ESLint: 8.54.0 - that means you're definitely not on ESLint's latest version (8.57.0 for v8 or 9.0.0 for v9) or our latest version (because the latest version explicitly has a dependency on at least ESLint v8.56.0).

So update your deps.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
@emily61268
Copy link
Author

I just updated the version to 8.57.0, still getting the same error.

@bradzacher
Copy link
Member

Of eslint, sure, what about our packages?

@emily61268
Copy link
Author

emily61268 commented Apr 17, 2024

Thank you for pointing this out. I realized that our ts-eslint packages were still 5.59.0, and the allow config was added after 6.0.0. I updated our ts-eslint packages to 7.7.0 and the issue was resolved. Thank you very much for your help!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 25, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants