Skip to content

Commit

Permalink
fix(eslint-plugin): isTypeReadonly stack overflow (typescript-eslint#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sviat9440 authored and Святослав Зайцев committed Oct 23, 2022
1 parent d14591c commit c924f43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
@@ -1,10 +1,12 @@
import type { TSESLint } from '@typescript-eslint/utils';
import * as a from 'a';

import rule from '../../src/rules/prefer-readonly-parameter-types';
import type {
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
} from '../../src/util';
import * as util from '../../src/util';
import { getFixturesRootDir, noFormat, RuleTester } from '../RuleTester';

type MessageIds = InferMessageIdsTypeFromRule<typeof rule>;
Expand Down Expand Up @@ -362,6 +364,23 @@ ruleTester.run('prefer-readonly-parameter-types', rule, {
},
],
},
{
name: 'circular readonly types (Bug: #4476)',
code: `
interface Obj {
readonly [K: string]: Obj;
}
function foo(event: Obj): void {}
`,
options: [
{
checkParameterProperties: true,
ignoreInferredTypes: false,
...util.readonlynessOptionsDefaults,
},
],
},
],
invalid: [
// arrays
Expand Down
4 changes: 4 additions & 0 deletions packages/type-utils/src/isTypeReadonly.ts
Expand Up @@ -113,6 +113,10 @@ function isTypeReadonlyObject(
return Readonlyness.Mutable;
}

if (indexInfo.type === type) {
return Readonlyness.Readonly;
}

return isTypeReadonlyRecurser(
checker,
indexInfo.type,
Expand Down

0 comments on commit c924f43

Please sign in to comment.