Skip to content

Commit 995af09

Browse files
authored
Recommend export = over export default in cjs declaration files (#3322)
1 parent e79ad53 commit 995af09

File tree

1 file changed

+2
-11
lines changed
  • packages/documentation/copy/en/declaration-files/templates

1 file changed

+2
-11
lines changed

packages/documentation/copy/en/declaration-files/templates/module.d.ts.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Which can be described by the following .d.ts:
5959

6060
```ts
6161
declare const helloWorld: RegExp;
62-
export default helloWorld;
62+
export = helloWorld;
6363
```
6464

6565
Or a number:
@@ -70,7 +70,7 @@ module.exports = 3.142;
7070

7171
```ts
7272
declare const pi: number;
73-
export default pi;
73+
export = pi;
7474
```
7575

7676
One style of exporting in CommonJS is to export a function.
@@ -87,15 +87,6 @@ module.exports = getArrayLength;
8787

8888
Which can be described with:
8989

90-
```ts
91-
export default function getArrayLength(arr: any[]): number;
92-
export const maxInterval: 12;
93-
```
94-
95-
Note that using `export default` in your .d.ts files requires [`esModuleInterop: true`](/tsconfig#esModuleInterop) to work.
96-
If you can't have `esModuleInterop: true` in your project, such as when you're submitting a PR to Definitely Typed, you'll have to use the `export=` syntax instead. This older syntax is harder to use but works everywhere.
97-
Here's how the above example would have to be written using `export=`:
98-
9990
```ts
10091
declare function getArrayLength(arr: any[]): number;
10192
declare namespace getArrayLength {

0 commit comments

Comments
 (0)