Skip to content

Commit

Permalink
fix(eslint-plugin): isTypeReadonly stack overflow (#4476)
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 67eba41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -5,6 +5,7 @@ import type {
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
} from '../../src/util';
import { readonlynessOptionsDefaults } from '../../src/util';
import { getFixturesRootDir, noFormat, RuleTester } from '../RuleTester';

type MessageIds = InferMessageIdsTypeFromRule<typeof rule>;
Expand Down Expand Up @@ -362,6 +363,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,
...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 67eba41

Please sign in to comment.