Skip to content

Commit 4f01bac

Browse files
authored
build: add lint rule to disallow type-only imports/exports (#24678)
Type-only imports and exports don't work with Closure so we can't use them.
1 parent 87ab4f4 commit 4f01bac

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ts from 'typescript';
2+
import * as Lint from 'tslint';
3+
4+
/** Lint rule that doesn't allow usages of type-only imports/exports. */
5+
export class Rule extends Lint.Rules.AbstractRule {
6+
apply(sourceFile: ts.SourceFile) {
7+
return this.applyWithFunction(sourceFile, walker);
8+
}
9+
}
10+
11+
function walker(context: Lint.WalkContext): void {
12+
(function visitNode(node: ts.Node) {
13+
if (ts.isTypeOnlyImportOrExportDeclaration(node)) {
14+
context.addFailureAtNode(node, 'Type-only symbols are not allowed.');
15+
}
16+
17+
ts.forEachChild(node, visitNode);
18+
})(context.sourceFile);
19+
}

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
// Custom Rules
7676
"ts-loader": true,
7777
"no-exposed-todo": true,
78+
"no-type-only-import-export": true,
7879
"no-private-getters": [true, "^_"],
7980
"no-undecorated-base-class-di": true,
8081
"no-undecorated-class-with-angular-features": true,

0 commit comments

Comments
 (0)