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(eslint-plugin): prefer-readonly-parameter-types] more isTypeReadonly stack overflow handling#5876

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/5875
Nov 2, 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@@ -380,6 +380,27 @@ ruleTester.run('prefer-readonly-parameter-types', rule, {
},
],
},
{
name: 'circular readonly types (Bug: #5875)',
code: `
interface Obj1 {
readonly [K: string]: Obj2;
}

interface Obj2 {
readonly [K: string]: Obj1;
}

function foo(event: Obj1): void {}
`,
options: [
{
checkParameterProperties: true,
ignoreInferredTypes: false,
...readonlynessOptionsDefaults,
},
],
},
],
invalid: [
// arrays
Expand Down
2 changes: 1 addition & 1 deletionpackages/type-utils/src/isTypeReadonly.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -113,7 +113,7 @@ function isTypeReadonlyObject(
return Readonlyness.Mutable;
}

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

Expand Down
22 changes: 21 additions & 1 deletionpackages/type-utils/tests/isTypeReadonly.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -139,6 +139,11 @@ describe('isTypeReadonly', () => {

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

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

describe('is not readonly', () => {
Expand All@@ -156,8 +161,23 @@ describe('isTypeReadonly', () => {
describe('is not readonly circular', () => {
const runTests = runTestIsNotReadonly;

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

it.each([
[
'interface Test1 { [key: string]: Test } interface Test { readonly [key: string]: Test1 }',
],
[
'interface Test1 { readonly [key: string]: Test } interface Test { [key: string]: Test1 }',
],
[
'interface Test1 { [key: string]: Test } interface Test { [key: string]: Test1 }',
],
])(
'handles circular mutable PropertySignature inside interdependent objects',
runTests,
);
});
});

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp