From a93a1e404c9b61b43c43d4dae1ca0a2e35899cdd Mon Sep 17 00:00:00 2001 From: Chema Balsas Date: Fri, 1 Jul 2022 07:34:12 +0100 Subject: [PATCH] fix: output complete type parameter for record generics --- .../src/rules/consistent-indexed-object-style.ts | 2 +- .../rules/consistent-indexed-object-style.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts index 3da9692df9e2..e4e73d897528 100644 --- a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts +++ b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts @@ -132,7 +132,7 @@ export default createRule({ if ((node.typeParameters?.params ?? []).length > 0) { genericTypes = `<${node.typeParameters?.params - .map(p => p.name.name) + .map(p => sourceCode.getText(p)) .join(', ')}>`; } diff --git a/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts b/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts index 9c92f1a2eac9..b02fd3dfa2db 100644 --- a/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts @@ -174,6 +174,19 @@ type Foo = Record; errors: [{ messageId: 'preferRecord', line: 2, column: 1 }], }, + // Interface with generic parameter and default value + { + code: ` +interface Foo { + [key: string]: A; +} + `, + output: ` +type Foo = Record; + `, + errors: [{ messageId: 'preferRecord', line: 2, column: 1 }], + }, + // Interface with extends { code: `