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

[prefer-readonly-parameter-types] Error with combination of type parameter, readonly array, and mapped type #1742

Closed
susisu opened this issue Mar 16, 2020 · 1 comment
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@susisu
Copy link
Contributor

susisu commented Mar 16, 2020

Repro

.eslintrc.json

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module",
    "project": "./tsconfig.json"
  },
  "rules": {
    "@typescript-eslint/prefer-readonly-parameter-types": ["error", { "checkParameterProperties": true }]
  }
}

tsconfig.json

{
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "lib",
    "strict": true
  },
  "include": [
    "src/**/*"
  ]
}

src/index.ts

type F<T> = { [K in keyof T]: T[K] };
function f<T extends readonly unknown[]>(x: F<T>): void {}

Expected Result
Lint finishes without throwing error.

Actual Result
TypeError: Cannot read property 'flags' of undefined is thrown.

Additional Info

$ eslint --ext .ts src --debug
  eslint:cli CLI args: [ '--ext', '.ts', 'src', '--debug' ] +0ms
  eslint:cli Running on files +3ms
  eslint:config-array-factory Loading JSON config file: /Users/susisu/Projects/sandbox/ts-eslint-test/package.json +0ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', patterns: [ '/node_modules/*', '/bower_components/*' ] } +1ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', loose: false } ] +1ms
  eslint:ignore-pattern   processed: { basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', patterns: [ '/node_modules/*', '/bower_components/*' ] } +0ms
  eslint:file-enumerator Start to iterate files: [ 'src' ] +0ms
  eslint:file-enumerator Directory: /Users/susisu/Projects/sandbox/ts-eslint-test/src +0ms
  eslint:file-enumerator Enter the directory: /Users/susisu/Projects/sandbox/ts-eslint-test/src +0ms
  eslint:cascading-config-array-factory Load config files for /Users/susisu/Projects/sandbox/ts-eslint-test/src. +0ms
  eslint:cascading-config-array-factory No cache found: /Users/susisu/Projects/sandbox/ts-eslint-test/src. +0ms
  eslint:config-array-factory Config file not found on /Users/susisu/Projects/sandbox/ts-eslint-test/src +5ms
  eslint:cascading-config-array-factory No cache found: /Users/susisu/Projects/sandbox/ts-eslint-test. +0ms
  eslint:config-array-factory Loading JSON config file: /Users/susisu/Projects/sandbox/ts-eslint-test/.eslintrc.json +0ms
  eslint:config-array-factory Config file found: /Users/susisu/Projects/sandbox/ts-eslint-test/.eslintrc.json +0ms
  eslint:config-array-factory Loading parser "@typescript-eslint/parser" from /Users/susisu/Projects/sandbox/ts-eslint-test/.eslintrc.json +1ms
  eslint:config-array-factory Loaded: @typescript-eslint/parser@2.23.1-alpha.7+71ef2670 (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/parser/dist/parser.js) +1ms
  eslint:config-array-factory Loading plugin "@typescript-eslint" from /Users/susisu/Projects/sandbox/ts-eslint-test/.eslintrc.json +191ms
  eslint:config-array-factory Loaded: @typescript-eslint/eslint-plugin@2.23.1-alpha.7+71ef2670 (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +2ms
  eslint:config-array-factory Plugin /Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 187ms +187ms
  eslint:cascading-config-array-factory No cache found: /Users/susisu/Projects/sandbox. +383ms
  eslint:config-array-factory Config file not found on /Users/susisu/Projects/sandbox +1ms
  eslint:cascading-config-array-factory No cache found: /Users/susisu/Projects. +0ms
  eslint:config-array-factory Config file not found on /Users/susisu/Projects +0ms
  eslint:cascading-config-array-factory No cache found: /Users/susisu. +0ms
  eslint:cascading-config-array-factory Stop traversing because of considered root. +0ms
  eslint:cascading-config-array-factory Configuration was determined: ConfigArray [ { name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { name: '.eslintrc.json', filePath: '/Users/susisu/Projects/sandbox/ts-eslint-test/.eslintrc.json', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/parser/dist/parser.js', id: '@typescript-eslint/parser', importerName: '.eslintrc.json', importerPath: '/Users/susisu/Projects/sandbox/ts-eslint-test/.eslintrc.json' }, parserOptions: { ecmaVersion: 2019, sourceType: 'module', project: './tsconfig.json' }, plugins: { '@typescript-eslint': [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { '@typescript-eslint/prefer-readonly-parameter-types': [Array] }, settings: undefined } ] on /Users/susisu/Projects/sandbox/ts-eslint-test/src +2ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', loose: false } ] +389ms
  eslint:ignore-pattern   processed: { basePath: '/Users/susisu/Projects/sandbox/ts-eslint-test', patterns: [ '/node_modules/*', '/bower_components/*' ] } +0ms
  eslint:ignore-pattern Check {
  filePath: '/Users/susisu/Projects/sandbox/ts-eslint-test/src/index.ts',
  dot: false,
  relativePath: 'src/index.ts',
  result: false
} +1ms
  eslint:file-enumerator Yield: index.ts +389ms
  eslint:cascading-config-array-factory Load config files for /Users/susisu/Projects/sandbox/ts-eslint-test/src. +3ms
  eslint:cascading-config-array-factory Cache hit: /Users/susisu/Projects/sandbox/ts-eslint-test/src. +0ms
  eslint:cli-engine Lint /Users/susisu/Projects/sandbox/ts-eslint-test/src/index.ts +0ms
  eslint:linter Linting code for /Users/susisu/Projects/sandbox/ts-eslint-test/src/index.ts (pass 1) +0ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: /Users/susisu/Projects/sandbox/ts-eslint-test/src/index.ts +0ms
  eslint:linter An error occurred while traversing +744ms
  eslint:linter Filename: /Users/susisu/Projects/sandbox/ts-eslint-test/src/index.ts +0ms
  eslint:linter Line: 2 +0ms
  eslint:linter Parser Options: {
  ecmaVersion: 10,
  sourceType: 'module',
  project: './tsconfig.json',
  ecmaFeatures: { globalReturn: false }
} +0ms
  eslint:linter Parser Path: /Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/parser/dist/parser.js +1ms
  eslint:linter Settings: {} +0ms
TypeError: Cannot read property 'flags' of undefined
Occurred while linting /Users/susisu/Projects/sandbox/ts-eslint-test/src/index.ts:2
    at Object.isUnionType (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/typeguard/2.8/type.js:69:18)
    at unionTypeParts (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:92:19)
    at isPropertyReadonlyInType (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:151:21)
    at isReadonlyPropertyFromMappedType (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:197:12)
    at /Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:179:21
    at someTypePart (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:100:52)
    at isReadonlyPropertyIntersection (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:172:12)
    at Object.isPropertyReadonlyInType (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/tsutils/util/type.js:161:43)
    at isTypeReadonlyObject (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:59:28)
    at isTypeReadonlyRecurser (/Users/susisu/Projects/sandbox/ts-eslint-test/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:114:30)

Versions

package version
@typescript-eslint/eslint-plugin 2.23.0 and 2.23.1-alpha.7
@typescript-eslint/parser 2.23.0 and 2.23.1-alpha.7
TypeScript 3.7.5
ESLint 6.8.0
node 12.14.1
npm 6.13.4
@susisu susisu added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 16, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Mar 16, 2020
@bradzacher
Copy link
Member

closing in favour of #3405 which is the same issue and has more comments

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants