Skip to content

Bug: [@typescript-eslint/prefer-readonly-parameter-types] <Can't ignore StyleProp> #11725

@RobinBobin

Description

@RobinBobin

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.9.2&fileType=.tsx&code=JYOwLgpgTgZghgYwgAgGrAgdwMpgJ4A2KA3sjBgQCYCMAXMiAK4C2ARtMgL4BQ%2BADigBicAgGc8yALzJGIShHIgIlZAB8GjAgTVkRolOoDkhgNzduoSLEQoAShASMoo4ADcIAQShQ4eADwAKgB83MjIEAAekHKiyF4%2B-gE69nCUAPYgBHjxvoFByQ5OLu45iUH5pDy8eALI9gDmwKJWyriEEHlSGmwcAGTIpAD6g1AQjc3QrfhEAEI%2BcvRJnGbVtW1EAApQaXydkqE6AQfqDU0tlOsdwcd1hc5unt65SSdjZ5MX01f56sJieCEwr89HgVggMs0yDAugAKA5wKD1OhoDA4L4AGnhiIATPRLlsdn50FhLiEAJT0VxpYAqSQVA7gkCiNJEAB0BDS9RhCKR6OQPOxZO4PCAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0Wls4CGAEwD2TeIVrEB0AQFtE%2BXrSKlUGANrhsOyL2gjokADTadWHZcgD48EQHd0YLZcsXXryFwNynXykgmZh66TPKIThqQAMpESAAKBsQmUABqlIj2sYSBwSEAunmWAL5FEIWupToVYKXFQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

interface ViewStyle { field1: number }
type Falsy = undefined | null | false | '';

interface RecursiveArray<T>
  extends Array<T | ReadonlyArray<T> | RecursiveArray<T>> { }

type RegisteredStyle<T> = number & { __registeredStyleBrand: T };

type StyleProp<T> =
  | T
  | RegisteredStyle<T>
  | RecursiveArray<T | RegisteredStyle<T> | Falsy>
  | Falsy;

const ff = (
  arg1: ViewStyle,
  arg2: StyleProp<ViewStyle>
): void => {
  console.log(arg1, arg2)
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/prefer-readonly-parameter-types": [
        "error",
      {
          "allow": [
          {
              "from": "file",
              "name": ["StyleProp", "ViewStyle"
            ]
          }
        ]
      }
    ]
  },
};

tsconfig

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

Expected Result

I expected ESLint won't issue Parameter should be a read only type for StyleProp<ViewStyle>.

Actual Result

ESLiint issued Parameter should be a read only type for StyleProp<ViewStyle> until I changed my allow option to be

allow: [
            {
              from: 'file',
              name: ['RecursiveArray', 'RegisteredStyle', 'ViewStyle']
            }
          ]

Additional Info

StyleProp and ViewStyle are types / interfaces from react-native.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions