Skip to content

Commit

Permalink
fix(eslint-plugin): [no-type-alias] consider type imports as alias ty…
Browse files Browse the repository at this point in the history
…pes (#3433)
  • Loading branch information
Josh Goldberg committed May 28, 2021
1 parent a760946 commit d4f0774
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/no-type-alias.ts
Expand Up @@ -122,6 +122,7 @@ export default util.createRule<Options, MessageIds>({
];
const aliasTypes = new Set([
AST_NODE_TYPES.TSArrayType,
AST_NODE_TYPES.TSImportType,
AST_NODE_TYPES.TSTypeReference,
AST_NODE_TYPES.TSLiteralType,
AST_NODE_TYPES.TSTypeQuery,
Expand Down
45 changes: 45 additions & 0 deletions packages/eslint-plugin/tests/rules/no-type-alias.test.ts
Expand Up @@ -394,6 +394,10 @@ export type ClassValue =
code: 'type Foo = typeof bar;',
options: [{ allowAliases: 'always' }],
},
{
code: "type Foo = typeof import('foo');",
options: [{ allowAliases: 'always' }],
},
{
code: `
const WithAKey = { AKey: true };
Expand All @@ -405,6 +409,10 @@ type KeyNames = keyof typeof SCALARS;
code: 'type Foo = typeof bar | typeof baz;',
options: [{ allowAliases: 'in-unions' }],
},
{
code: "type Foo = typeof bar | typeof import('foo');",
options: [{ allowAliases: 'in-unions' }],
},
{
code: 'type Foo = keyof [string];',
options: [{ allowTupleTypes: 'always' }],
Expand Down Expand Up @@ -505,6 +513,20 @@ type KeyNames = keyof typeof SCALARS;
},
],
},
{
code: "type Foo = typeof import('foo');",
options: [{ allowAliases: 'never' }],
errors: [
{
messageId: 'noTypeAlias',
data: {
alias: 'aliases',
},
line: 1,
column: 12,
},
],
},
{
code: "type Foo = 'a' | 'b';",
errors: [
Expand All @@ -528,6 +550,29 @@ type KeyNames = keyof typeof SCALARS;
},
],
},
{
code: "type Foo = 'a' | typeof import('foo');",
errors: [
{
messageId: 'noCompositionAlias',
data: {
typeName: 'Aliases',
compositionType: 'union',
},
line: 1,
column: 12,
},
{
messageId: 'noCompositionAlias',
data: {
typeName: 'Aliases',
compositionType: 'union',
},
line: 1,
column: 18,
},
],
},
{
code: "type Foo = 'a' | 'b';",
options: [{ allowLiterals: 'in-unions' }],
Expand Down

0 comments on commit d4f0774

Please sign in to comment.