Skip to content

Commit 31ba71a

Browse files
committed
Fix generated namespace types in index.d.ts
Previously some namespace types were generated using the legacy `module` keyword from ten years ago. Now we emit the modern TS `namespace` keyword that has been the preferred keyword since TypeScript 1.5 in 2015. Please review the resulting diff for the generated `dist/index.d.ts` file: https://gist.github.com/robpalme/a320dc3f0cb50bcd14962bca46827dae/revisions Note that the outer _Ambient Module Declaration_ intentionally remains untouched because it is not a namespace. These are differentiated by using a quoted string rather than a bare identifier `module "quoted" {` vs `module bare {}` --- Background: This usage of the legacy keyword was found by [a TypeScript real-world test suite](microsoft/TypeScript#61450 (comment)) that checks the compatibility of proposed changes. Using the `module` keyword for namespaces is [proposed for deprecation in TypeScript 6.0](microsoft/TypeScript#54500 (comment)) so it's worth getting ahead of this.
1 parent 4e312f3 commit 31ba71a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

utils/bundle-dts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (typingsLength == typings.length)
1919
// Rename common module to glMatrix
2020
typings = typings.replace(
2121
'declare module "common" {',
22-
"export module glMatrix {"
22+
"export namespace glMatrix {"
2323
);
2424

2525
// Replace imports from other modules with direct references
@@ -29,7 +29,7 @@ typings = typings.replace(/import\("([^"]+?)(\.js)?"\)/g, "$1");
2929
typings = typings.replace(/ *import.+from.*;/g, "");
3030

3131
// Replace declare module with exports
32-
typings = typings.replace(/declare module "([^"]+?)" {/g, "export module $1 {");
32+
typings = typings.replace(/declare module "([^"]+?)" {/g, "export namespace $1 {");
3333

3434
// Add types
3535
typings = "\n" + sourceTypings.replace(/declare/g, "export") + "\n" + typings;

0 commit comments

Comments
 (0)