Skip to content

Commit

Permalink
fix(eslint-plugin): [consistent-indexed-object-style] fix record mode…
Browse files Browse the repository at this point in the history
… fixer for generics with a default value (#5280)
  • Loading branch information
jbalsas committed Jul 4, 2022
1 parent e7fd10c commit 57f032c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -132,7 +132,7 @@ export default createRule<Options, MessageIds>({

if ((node.typeParameters?.params ?? []).length > 0) {
genericTypes = `<${node.typeParameters?.params
.map(p => p.name.name)
.map(p => sourceCode.getText(p))
.join(', ')}>`;
}

Expand Down
Expand Up @@ -174,6 +174,19 @@ type Foo<A> = Record<string, A>;
errors: [{ messageId: 'preferRecord', line: 2, column: 1 }],
},

// Interface with generic parameter and default value
{
code: `
interface Foo<A = any> {
[key: string]: A;
}
`,
output: `
type Foo<A = any> = Record<string, A>;
`,
errors: [{ messageId: 'preferRecord', line: 2, column: 1 }],
},

// Interface with extends
{
code: `
Expand Down

0 comments on commit 57f032c

Please sign in to comment.