From e2e783959fac3cccae99bf05f6cec70c7602552a Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Tue, 6 May 2025 16:45:05 +0300 Subject: [PATCH 1/2] initial implementation --- .../src/rules/consistent-indexed-object-style.ts | 6 +++--- .../rules/consistent-indexed-object-style.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) 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 3b8130097218..51c186a3ba3d 100644 --- a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts +++ b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts @@ -226,9 +226,9 @@ export default createRule({ ...(canFix && { fix: (fixer): ReturnType => { const keyType = context.sourceCode.getText(constraint); - const valueType = context.sourceCode.getText( - node.typeAnnotation, - ); + const valueType = node.typeAnnotation + ? context.sourceCode.getText(node.typeAnnotation) + : 'any'; let recordText = `Record<${keyType}, ${valueType}>`; 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 5ecceba510a3..f309f8bb07ad 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 @@ -904,5 +904,17 @@ interface Bar { } `, }, + + { + code: ` +type Bar = { + [k in string]; +}; + `, + errors: [{ column: 12, line: 2, messageId: 'preferRecord' }], + output: ` +type Bar = Record; + `, + }, ], }); From ccd2307316b70a02a3fe6b2d4c14b7adfcbedf09 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Tue, 6 May 2025 17:43:11 +0300 Subject: [PATCH 2/2] naming --- .../tests/rules/consistent-indexed-object-style.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f309f8bb07ad..2d8b24585827 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 @@ -907,13 +907,13 @@ interface Bar { { code: ` -type Bar = { +type Foo = { [k in string]; }; `, errors: [{ column: 12, line: 2, messageId: 'preferRecord' }], output: ` -type Bar = Record; +type Foo = Record; `, }, ], pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy