From 7aace1e10f5a57e1a806de806da6c6f1f1efee97 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 2 Feb 2025 20:51:06 -0500 Subject: [PATCH 1/3] Recommend `export =` over `export default` in cjs declaration files --- .../declaration-files/templates/module.d.ts.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md b/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md index 70ed595c6b0f..5b14ccad69fc 100644 --- a/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md +++ b/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md @@ -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: @@ -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. @@ -87,21 +87,11 @@ 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 { - declare const maxInterval: 12; + declare const maxInterval: 12; } - export = getArrayLength; ``` From 3c931c4aadb967d81c3fe73003dceedfff68a305 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 2 Feb 2025 20:52:32 -0500 Subject: [PATCH 2/3] spacing --- .../copy/en/declaration-files/templates/module.d.ts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md b/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md index 5b14ccad69fc..45b1230dfd69 100644 --- a/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md +++ b/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md @@ -90,7 +90,7 @@ Which can be described with: ```ts declare function getArrayLength(arr: any[]): number; declare namespace getArrayLength { - declare const maxInterval: 12; + declare const maxInterval: 12; } export = getArrayLength; ``` From dd2c1707576dd53842d75a0bbe7c36e3e5e9fd73 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 2 Feb 2025 20:54:24 -0500 Subject: [PATCH 3/3] add back blank line --- .../copy/en/declaration-files/templates/module.d.ts.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md b/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md index 45b1230dfd69..3b54a644fac1 100644 --- a/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md +++ b/packages/documentation/copy/en/declaration-files/templates/module.d.ts.md @@ -92,6 +92,7 @@ declare function getArrayLength(arr: any[]): number; declare namespace getArrayLength { declare const maxInterval: 12; } + export = getArrayLength; ```