Skip to content

Commit

Permalink
fix(eslint-plugin): [consistent-indexed-object-style] handle interfac…
Browse files Browse the repository at this point in the history
…e generic (#5746)

* fix(eslint-plugin): [consistent-indexed-object-style] handle interface generic

* fix lint error
  • Loading branch information
yeonjuan authored Oct 5, 2022
1 parent 93bf147 commit 7a8a0a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';

import { createRule } from '../util';

Expand Down Expand Up @@ -67,7 +67,7 @@ export default createRule<Options, MessageIds>({

if (parentId) {
const scope = context.getScope();
const superVar = scope.set.get(parentId.name);
const superVar = ASTUtils.findVariable(scope, parentId.name);
if (superVar) {
const isCircular = superVar.references.some(
item =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ interface Foo {
[key: string]: Foo;
}
`,

`
interface Foo<T> {
[key: string]: Foo<T>;
}
`,
`
interface Foo<T> {
[key: string]: Foo<T> | string;
}
`,
// Type literal
'type Foo = {};',
`
Expand Down Expand Up @@ -328,6 +337,17 @@ type Foo<A, B> = Readonly<Record<A, B>>;
},
{
code: `
interface Foo<T> {
[k: string]: T;
}
`,
output: `
type Foo<T> = Record<string, T>;
`,
errors: [{ messageId: 'preferRecord', line: 2, column: 1 }],
},
{
code: `
interface Foo {
[k: string]: A.Foo;
}
Expand Down

0 comments on commit 7a8a0a3

Please sign in to comment.