Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Oct 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
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