Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 329ef02

Browse files
author
Josh Goldberg
authored
fix(eslint-plugin): [no-type-alias] consider keyof as an alias (typescript-eslint#3242)
1 parent 265a039 commit 329ef02

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/eslint-plugin/src/rules/no-type-alias.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ export default util.createRule<Options, MessageIds>({
264264
type.node.type.endsWith('Keyword') ||
265265
aliasTypes.has(type.node.type) ||
266266
(type.node.type === AST_NODE_TYPES.TSTypeOperator &&
267-
type.node.operator === 'readonly' &&
268-
type.node.typeAnnotation &&
269-
aliasTypes.has(type.node.typeAnnotation.type))
267+
(type.node.operator === 'keyof' ||
268+
(type.node.operator === 'readonly' &&
269+
type.node.typeAnnotation &&
270+
aliasTypes.has(type.node.typeAnnotation.type))))
270271
) {
271272
// alias / keyword
272273
checkAndReport(allowAliases!, isTopLevel, type, 'Aliases');

packages/eslint-plugin/tests/rules/no-type-alias.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ export type ClassValue =
394394
code: 'type Foo = typeof bar;',
395395
options: [{ allowAliases: 'always' }],
396396
},
397+
{
398+
code: `
399+
const WithAKey = { AKey: true };
400+
type KeyNames = keyof typeof SCALARS;
401+
`,
402+
options: [{ allowAliases: 'always' }],
403+
},
397404
{
398405
code: 'type Foo = typeof bar | typeof baz;',
399406
options: [{ allowAliases: 'in-unions' }],

0 commit comments

Comments
 (0)