Skip to content

Commit

Permalink
fix(eslint-plugin): [no-type-alias] consider keyof as an alias (#3242)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg committed Mar 29, 2021
1 parent 265a039 commit 329ef02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/eslint-plugin/src/rules/no-type-alias.ts
Expand Up @@ -264,9 +264,10 @@ export default util.createRule<Options, MessageIds>({
type.node.type.endsWith('Keyword') ||
aliasTypes.has(type.node.type) ||
(type.node.type === AST_NODE_TYPES.TSTypeOperator &&
type.node.operator === 'readonly' &&
type.node.typeAnnotation &&
aliasTypes.has(type.node.typeAnnotation.type))
(type.node.operator === 'keyof' ||
(type.node.operator === 'readonly' &&
type.node.typeAnnotation &&
aliasTypes.has(type.node.typeAnnotation.type))))
) {
// alias / keyword
checkAndReport(allowAliases!, isTopLevel, type, 'Aliases');
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-plugin/tests/rules/no-type-alias.test.ts
Expand Up @@ -394,6 +394,13 @@ export type ClassValue =
code: 'type Foo = typeof bar;',
options: [{ allowAliases: 'always' }],
},
{
code: `
const WithAKey = { AKey: true };
type KeyNames = keyof typeof SCALARS;
`,
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = typeof bar | typeof baz;',
options: [{ allowAliases: 'in-unions' }],
Expand Down

0 comments on commit 329ef02

Please sign in to comment.