Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend export = over export default in cjs declaration files #3322

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Which can be described by the following .d.ts:

```ts
declare const helloWorld: RegExp;
export default helloWorld;
export = helloWorld;
```

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

```ts
declare const pi: number;
export default pi;
export = pi;
```

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

Which can be described with:

```ts
export default function getArrayLength(arr: any[]): number;
export const maxInterval: 12;
```

Note that using `export default` in your .d.ts files requires [`esModuleInterop: true`](/tsconfig#esModuleInterop) to work.
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.
Here's how the above example would have to be written using `export=`:

```ts
declare function getArrayLength(arr: any[]): number;
declare namespace getArrayLength {
Expand Down