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): [consistent-indexed-object-style] check for indirect circular types in aliased mapped types#11177

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
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@@ -205,11 +205,10 @@ export default createRule<Options, MessageIds>({
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],
const isCircular = isDeeplyReferencingType(
node.parent,
superVar,
new Set([parentId]),
);
if (isCircular) {
return;
Expand DownExpand Up@@ -291,6 +290,12 @@ function isDeeplyReferencingType(
return [node.indexType, node.objectType].some(type =>
isDeeplyReferencingType(type, superVar, visited),
);
case AST_NODE_TYPES.TSMappedType:
if (node.typeAnnotation) {
return isDeeplyReferencingType(node.typeAnnotation, superVar, visited);
}

break;
case AST_NODE_TYPES.TSConditionalType:
return [
node.checkType,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,6 +174,18 @@ interface ExampleObject {
[key: string]: ExampleRoot;
}
`,
`
type Bar<K extends string = never> = {
[k in K]: Bar;
};
`,
`
type Bar<K extends string = never> = {
[k in K]: Foo;
};

type Foo = Bar;
`,

// Type literal
'type Foo = {};',
Expand DownExpand Up@@ -646,6 +658,36 @@ type Foo2 = Record<string, Foo3>;
type Foo3 = Record<string, Record<string, Foo1>>;
`,
},
{
code: `
type Foos<K extends string = never> = {
[k in K]: { foo: Foo };
};

type Foo = Foos;
`,
errors: [{ column: 39, line: 2, messageId: 'preferRecord' }],
output: `
type Foos<K extends string = never> = Record<K, { foo: Foo }>;

type Foo = Foos;
`,
},
{
code: `
type Foos<K extends string = never> = {
[k in K]: Foo[];
};

type Foo = Foos;
`,
errors: [{ column: 39, line: 2, messageId: 'preferRecord' }],
output: `
type Foos<K extends string = never> = Record<K, Foo[]>;

type Foo = Foos;
`,
},

// Generic
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp