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

Skip to content

Commit d4f0774

Browse files
author
Josh Goldberg
authored
fix(eslint-plugin): [no-type-alias] consider type imports as alias types (typescript-eslint#3433)
1 parent a760946 commit d4f0774

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default util.createRule<Options, MessageIds>({
122122
];
123123
const aliasTypes = new Set([
124124
AST_NODE_TYPES.TSArrayType,
125+
AST_NODE_TYPES.TSImportType,
125126
AST_NODE_TYPES.TSTypeReference,
126127
AST_NODE_TYPES.TSLiteralType,
127128
AST_NODE_TYPES.TSTypeQuery,

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ export type ClassValue =
394394
code: 'type Foo = typeof bar;',
395395
options: [{ allowAliases: 'always' }],
396396
},
397+
{
398+
code: "type Foo = typeof import('foo');",
399+
options: [{ allowAliases: 'always' }],
400+
},
397401
{
398402
code: `
399403
const WithAKey = { AKey: true };
@@ -405,6 +409,10 @@ type KeyNames = keyof typeof SCALARS;
405409
code: 'type Foo = typeof bar | typeof baz;',
406410
options: [{ allowAliases: 'in-unions' }],
407411
},
412+
{
413+
code: "type Foo = typeof bar | typeof import('foo');",
414+
options: [{ allowAliases: 'in-unions' }],
415+
},
408416
{
409417
code: 'type Foo = keyof [string];',
410418
options: [{ allowTupleTypes: 'always' }],
@@ -505,6 +513,20 @@ type KeyNames = keyof typeof SCALARS;
505513
},
506514
],
507515
},
516+
{
517+
code: "type Foo = typeof import('foo');",
518+
options: [{ allowAliases: 'never' }],
519+
errors: [
520+
{
521+
messageId: 'noTypeAlias',
522+
data: {
523+
alias: 'aliases',
524+
},
525+
line: 1,
526+
column: 12,
527+
},
528+
],
529+
},
508530
{
509531
code: "type Foo = 'a' | 'b';",
510532
errors: [
@@ -528,6 +550,29 @@ type KeyNames = keyof typeof SCALARS;
528550
},
529551
],
530552
},
553+
{
554+
code: "type Foo = 'a' | typeof import('foo');",
555+
errors: [
556+
{
557+
messageId: 'noCompositionAlias',
558+
data: {
559+
typeName: 'Aliases',
560+
compositionType: 'union',
561+
},
562+
line: 1,
563+
column: 12,
564+
},
565+
{
566+
messageId: 'noCompositionAlias',
567+
data: {
568+
typeName: 'Aliases',
569+
compositionType: 'union',
570+
},
571+
line: 1,
572+
column: 18,
573+
},
574+
],
575+
},
531576
{
532577
code: "type Foo = 'a' | 'b';",
533578
options: [{ allowLiterals: 'in-unions' }],

0 commit comments

Comments
 (0)