UNPKG

1.34 kBMarkdownView Raw
1# `no-useless-empty-export`
2
3Disallow empty exports that don't change anything in a module file.
4
5## Rule Details
6
7An empty `export {}` statement is sometimes useful in TypeScript code to turn a file that would otherwise be a script file into a module file.
8Per the TypeScript Handbook [Modules](https://www.typescriptlang.org/docs/handbook/modules.html) page:
9
10> In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module.
11> Conversely, a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope (and therefore to modules as well).
12
13However, an `export {}` statement does nothing if there are any other top-level import or export statements in a file.
14
15Examples of code for this rule:
16
17<!--tabs-->
18
19### ❌ Incorrect
20
21```ts
22export const value = 'Hello, world!';
23export {};
24```
25
26```ts
27import 'some-other-module';
28export {};
29```
30
31### ✅ Correct
32
33```ts
34export const value = 'Hello, world!';
35```
36
37```ts
38import 'some-other-module';
39```
40
41## Options
42
43```jsonc
44// .eslintrc.json
45{
46 "rules": {
47 "@typescript-eslint/no-useless-empty-export": "warn"
48 }
49}
50```
51
52This rule is not configurable.
53
54## Attributes
55
56- Configs:
57 - [ ] ✅ Recommended
58 - [ ] 🔒 Strict
59- [x] 🔧 Fixable
60- [ ] 💭 Requires type information