Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(type-utils): prevent stack overflow inisTypeReadonly#5860

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 2 commits intotypescript-eslint:mainfromMillerSvt:fix/4476
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
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 DownExpand 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 deletionspackages/type-utils/src/isTypeReadonly.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
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
14 changes: 14 additions & 0 deletionspackages/type-utils/tests/isTypeReadonly.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,6 +134,13 @@ describe('isTypeReadonly', () => {
);
});

describe('is readonly circular', () => {
const runTests = runTestIsReadonly;

it('handles circular readonly PropertySignature inside a readonly IndexSignature', () =>
runTests('interface Test { readonly [key: string]: Test };'));
});

describe('is not readonly', () => {
const runTests = runTestIsNotReadonly;

Expand All@@ -145,6 +152,13 @@ describe('isTypeReadonly', () => {
runTests,
);
});

describe('is not readonly circular', () => {
const runTests = runTestIsNotReadonly;

it('handles circular mutable PropertySignature inside a readonly IndexSignature', () =>
runTests('interface Test { [key: string]: Test };'));
});
});

describe('Union', () => {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp