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

Commite0e68c2

Browse files
fix(eslint-plugin): [consistent-indexed-object-style] handle circular mapped types
1 parentbce4560 commite0e68c2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

‎packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ export default createRule<Options, MessageIds>({
176176
return;
177177
}
178178

179+
// If the mapped type is circular, we can't convert it to a Record.
180+
constparentId=findParentDeclaration(node)?.id;
181+
if(parentId){
182+
constscope=context.sourceCode.getScope(key);
183+
constsuperVar=ASTUtils.findVariable(scope,parentId.name);
184+
if(superVar){
185+
constisCircular=superVar.references.some(
186+
item=>
187+
item.isTypeReference&&
188+
node.range[0]<=item.identifier.range[0]&&
189+
node.range[1]>=item.identifier.range[1],
190+
);
191+
if(isCircular){
192+
return;
193+
}
194+
}
195+
}
196+
179197
// There's no builtin Mutable<T> type, so we can't autofix it really.
180198
constcanFix=node.readonly!=='-';
181199

‎packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface Foo {
3333
'type Foo = { [key: string]: string | Foo };',
3434
'type Foo = { [key: string]: Foo };',
3535
'type Foo = { [key: string]: Foo } | Foo;',
36+
'type Foo = { [key in string]: Foo };',
3637
`
3738
interface Foo {
3839
[key: string]: Foo;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp