Closed
Description
Hello, prefer-readonly-parameter-types
rule seems to crash in certain cases. This issue was spotted by automated CI run - it is not blocking my development or anything.
- 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
// .eslintrc.js
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
},
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/prefer-readonly-parameter-types": "error",
},
};
// tsconfig.json
{
"compilerOptions": {
"target": "es6",
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist"
},
"include": ["./index.ts"]
}
This is as minimal as I could narrow the issue down.
type MyType<T> = {
[K in keyof T]: "cat" | "dog" | T[K];
};
function method<A extends any[] = string[]>(value: MyType<A>) {
return value;
}
method(["cat", "dog"]);
method<"mouse"[]>(["cat", "mouse"]);
Expected Result
ESLint should not crash.
Actual Result
TypeError: Cannot read property 'flags' of undefined
Occurred while linting /workspaces/eslint-remote-tester/node_modules/.cache-eslint-remote-tester/querycap/webappkit/@querycap/reactutils/must.tsx:7
at Object.isUnionType (/workspaces/eslint-remote-tester/node_modules/tsutils/typeguard/2.8/type.js:69:18)
at unionTypeParts (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:92:19)
at isPropertyReadonlyInType (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:151:21)
at isReadonlyPropertyFromMappedType (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:197:12)
at /workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:179:21
at someTypePart (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:100:52)
at isReadonlyPropertyIntersection (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:172:12)
at Object.isPropertyReadonlyInType (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:161:43)
at isTypeReadonlyObject (/workspaces/eslint-remote-tester/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:72:28)
at isTypeReadonlyRecurser (/workspaces/eslint-remote-tester/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:127:30)
Additional Info
Crash reports from real projects
Rule: prefer-readonly-parameter-types
- Message:
Cannot read property 'flags' of undefined Occurred while linting /workspaces/eslint-remote-tester/node_modules/.cache-eslint-remote-tester/querycap/webappkit/@querycap/reactutils/must.tsx:7
- Path:
querycap/webappkit/@querycap/reactutils/must.tsx
- Link
5 |
6 | export function must<TPrepare extends Readonly<Array<any>>>(usePrepare: () => TPrepare) {
> 7 | return function <TProps>(render: (props: TProps, ...prepare: NonNullableArray<TPrepare>) => JSX.Element | null) {
8 | const C = ({ "data-prepare": dataPrepare, ...props }: TProps & { ["data-prepare"]: NonNullableArray<TPrepare> }) =>
9 | render(props as any, ...(dataPrepare as any));
10 |
TypeError: Cannot read property 'flags' of undefined
Occurred while linting /workspaces/eslint-remote-tester/node_modules/.cache-eslint-remote-tester/querycap/webappkit/@querycap/reactutils/must.tsx:7
at Object.isUnionType (/workspaces/eslint-remote-tester/node_modules/tsutils/typeguard/2.8/type.js:69:18)
at unionTypeParts (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:92:19)
at isPropertyReadonlyInType (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:151:21)
at isReadonlyPropertyFromMappedType (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:197:12)
at /workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:179:21
at someTypePart (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:100:52)
at isReadonlyPropertyIntersection (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:172:12)
at Object.isPropertyReadonlyInType (/workspaces/eslint-remote-tester/node_modules/tsutils/util/type.js:161:43)
at isTypeReadonlyObject (/workspaces/eslint-remote-tester/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:72:28)
at isTypeReadonlyRecurser (/workspaces/eslint-remote-tester/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:127:30)
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
4.23.0 |
@typescript-eslint/parser |
4.23.0 |
TypeScript |
4.2.4 |
ESLint |
7.26.0 |
node |
v14.15.1 |