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..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 @@ -904,5 +904,17 @@ interface Bar { } `, }, + + { + code: ` +type Foo = { + [k in string]; +}; + `, + errors: [{ column: 12, line: 2, messageId: 'preferRecord' }], + output: ` +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