Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ export default createRule<Options, MessageIds>({
return;
}

// If the mapped type is circular, we can't convert it to a Record.
const parentId = findParentDeclaration(node)?.id;
if (parentId) {
const scope = context.sourceCode.getScope(key);
const superVar = ASTUtils.findVariable(scope, parentId.name);
if (superVar) {
const isCircular = superVar.references.some(
item =>
item.isTypeReference &&
node.range[0] <= item.identifier.range[0] &&
node.range[1] >= item.identifier.range[1],
);
if (isCircular) {
return;
}
}
}

// There's no builtin Mutable<T> type, so we can't autofix it really.
const canFix = node.readonly !== '-';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface Foo {
'type Foo = { [key: string]: string | Foo };',
'type Foo = { [key: string]: Foo };',
'type Foo = { [key: string]: Foo } | Foo;',
'type Foo = { [key in string]: Foo };',
`
interface Foo {
[key: string]: Foo;
Expand Down
Loading