`prefer-immutable-types` crashes on Next.js `GetStaticPropsContext` type
Type: Bug
### Why the issue was filed?
Running ESLint with eslint-plugin-functional's rule `functional/prefer-immutable-types` on a Next.js page crashes ESLint with "ErrorType encountered." when the rule analyzes a parameter typed with Next's `GetStaticPropsContext<T>`. This occurs only in type-aware mode (parserOptions.project set); locally without type-aware linting on pages it does not crash, but in CI it does.
### Expected behavior
The rule should not crash when encountering TypeScript's internal `ErrorType` during type analysis. It should safely treat unknown/unresolvable types as "Unknown" or skip and either report no violation or a normal diagnostic, without throwing.
### Actual behavior
ESLint process exits with an error when linting the file:
```text
ESLint: 8.56.0
Error: ErrorType encountered.
Occurred while linting /home/runner/_work/agora/agora/src/pages/dummyPage.tsx:8
Rule: "functional/prefer-immutable-types"
at getTypeData (/home/runner/_work/agora/agora/node_modules/is-immutable-type/dist/index.cjs:118:15)
at Object.getTypeImmutability (/home/runner/_work/agora/agora/node_modules/is-immutable-type/dist/index.cjs:378:22)
at getTypeImmutabilityOfNode (/home/runner/_work/agora/agora/node_modules/eslint-plugin-functional/lib/classic.cjs:850:28)
at /home/runner/_work/agora/agora/node_modules/eslint-plugin-functional/lib/classic.cjs:2774:30
at Array.map (<anonymous>)
at getParameterTypeViolations (/home/runner/_work/agora/agora/node_modules/eslint-plugin-functional/lib/classic.cjs:2739:10)
at checkFunction$1 (/home/runner/_work/agora/agora/node_modules/eslint-plugin-functional/lib/classic.cjs:2891:12)
```
The crash occurs when the rule analyzes a function parameter typed with `GetStaticPropsContext<PageParams>`.
### Steps to reproduce
**Environment:**
- Node: 22
- TypeScript: 5.7.2
- ESLint: 8.56.0
- @typescript-eslint/parser: 5.62.0
- eslint-plugin-functional: 6.6.0
- next: 12.3.4
**ESLint config (from .eslintrc.js):**
```javascript
{
settings: {
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
},
},
rules: {
'functional/prefer-immutable-types': [
'error',
{
enforcement: 'ReadonlyShallow',
ignoreInferredTypes: true,
variables: {
enforcement: 'None',
},
fixer: {
ReadonlyShallow: [
{
pattern: '^([_$a-zA-Z\\xA0-\\uFFFF][_$a-zA-Z0-9\\xA0-\\uFFFF]*\\[\\])$',
replace: 'readonly $1',
},
{
pattern: '^(Array|Map|Set)<(.+)>$',
replace: 'Readonly$1<$2>',
},
{
pattern: '^(.+)$',
replace: 'Readonly<$1>',
},
],
},
},
],
},
}
```
Note: wrapping the type with `Readonly<>` has no effect on the crash.
**Minimal reproduction file:**
```typescript
import type { GetStaticPropsContext } from 'next';
type PageParams = {
gameId: string;
tournamentId: string;
};
export async function getStaticProps(
props: GetStaticPropsContext<PageParams>
) {
const { gameId, tournamentId } = props.params!;
return { props: {} as const };
}
```
**Run:**
```bash
npx eslint --max-warnings=0 src/pages/dummyPage.tsx
```
1 条评论