Repository: pyodide/pyodide
Pull request: Fix type declarations
Hopefully resolves #2395.

Problem statement:
In pyodide 0.20.0, pyodide.d.ts only exports `loadPyodide`
With pyodide 0.19.0 (installed from the release tarball), the pyodide.d.ts file exported many types, including `PyProxy`, `PyProxyCallable`, and `loadPyodide`. As of 0.20.0, that file only exports `loadPyodide`. Is that intentional? Some of those types were useful for some TypeScript code I've been working on. 

In a similar vein, there previously were a few other .d.ts files included in the distrubution, like api.d.ts and pyproxy.gen.d.ts, but those files are no longer there. It wasn't clear to me exactly what the structure/purpose of these .d.ts files was, but I did make use of some of them.

Hints from issue discussion:
Thanks for the report! 

No it's not intentional. We want to be exporting those other types. We can include them again in 0.20.1. We don't want the other files like api.d.ts, everything should be in the one file pyodide.d.ts The problem is we don't really know how to use typescript.
In `pyodide.ts` we say `export { ...,  PyProxyCallable, ... } from "./pyproxy.gen"`. `pyodide.d.ts` contains `type PyProxyCallable = ...` but then it doesn't export it. I wonder why.
Okay, if I run `tsc` it creates the old situation of many `.d.ts` files, but we really want them bundled together so that people don't end up relying on internal details of our project structure.
dts-bundle-generator seems to work correctly.

Commit message: Fix type declarations

Patch to review:
diff --git a/Makefile b/Makefile
index b4c27666577..31b832fd318 100644
--- a/Makefile
+++ b/Makefile
@@ -79,6 +79,9 @@ node_modules/.installed : src/js/package.json src/js/package-lock.json
 dist/pyodide.js: src/js/*.ts src/js/pyproxy.gen.ts src/js/error_handling.gen.ts node_modules/.installed
 	npx rollup -c src/js/rollup.config.js
 
+dist/pyodide.d.ts: src/js/*.ts src/js/pyproxy.gen.ts src/js/error_handling.gen.ts
+	npx dts-bundle-generator -o my.d.ts pyodide.ts --export-referenced-types false
+
 src/js/error_handling.gen.ts : src/core/error_handling.ts
 	cp $< $@
 
diff --git a/src/js/package-lock.json b/src/js/package-lock.json
index 3bdc0fa4ba8..9d06d82352e 100644
--- a/src/js/package-lock.json
+++ b/src/js/package-lock.json
@@ -980,6 +980,71 @@
         "is-obj": "^2.0.0"
       }
     },
+    "dts-bundle-generator": {
+      "version": "6.7.0",
+      "resolved": "https://registry.npmjs.org/dts-bundle-generator/-/dts-bundle-generator-6.7.0.tgz",
+      "integrity": "sha512-Rg46ug107sbdQ9cY3Z54lUHixzrt3cZULInEGq0aYxm36UoKIEoPh1jPt/9qoHqZ1cUFmSOIpVfEbds68lhdJw==",
+      "dev": true,
+      "requires": {
+        "typescript": ">=3.0.1",
+        "yargs": "^17.2.1"
+      },
+      "dependencies": {
+        "ansi-regex": {
+          "version": "5.0.1",
+          "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
+          "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
+          "dev": true
+        },
+        "is-fullwidth-code-point": {
+          "version": "3.0.0",
+          "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
+          "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
+          "dev": true
+        },
+        "string-width": {
+          "version": "4.2.3",
+          "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
+          "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
+          "dev": true,
+          "requires": {
+            "emoji-regex": "^8.0.0",
+            "is-fullwidth-code-point": "^3.0.0",
+            "strip-ansi": "^6.0.1"
+          }
+        },
+        "strip-ansi": {
+          "version": "6.0.1",
+          "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
+          "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
+          "dev": true,
+          "requires": {
+            "ansi-regex": "^5.0.1"
+          }
+        },
+        "yargs": {
+          "version": "17.4.1",
+          "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.4.1.tgz",
+          "integrity": "sha512-WSZD9jgobAg3ZKuCQZSa3g9QOJeCCqLoLAykiWgmXnDo9EPnn4RPf5qVTtzgOx66o6/oqhcA5tHtJXpG8pMt3g==",
+          "dev": true,
+          "requires": {
+            "cliui": "^7.0.2",
+            "escalade": "^3.1.1",
+            "get-caller-file": "^2.0.5",
+            "require-directory": "^2.1.1",
+            "string-width": "^4.2.3",
+            "y18n": "^5.0.5",
+            "yargs-parser": "^21.0.0"
+          }
+        },
+        "yargs-parser": {
+          "version": "21.0.1",
+          "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.0.1.tgz",
+          "integrity": "sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==",
+          "dev": true
+        }
+      }
+    },
     "duplexer3": {
       "version": "0.1.4",
       "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
diff --git a/src/js/package.json b/src/js/package.json
index e926e7456fc..cba50f51bc9 100644
--- a/src/js/package.json
+++ b/src/js/package.json
@@ -1,6 +1,6 @@
 {
   "name": "pyodide",
-  "version": "0.20.0",
+  "version": "0.20.0-dev.0",
   "description": "The Pyodide JavaScript package",
   "keywords": [
     "python",
@@ -20,6 +20,7 @@
     "@rollup/plugin-node-resolve": "^13.1.3",
     "@types/emscripten": "^1.39.5",
     "@types/node-fetch": "^3.0.3",
+    "dts-bundle-generator": "^6.7.0",
     "error-stack-parser": "^2.0.6",
     "mocha": "^9.0.2",
     "prettier": "^2.2.1",
@@ -29,8 +30,8 @@
     "terser": "^5.7.0",
     "ts-node": "^10.4.0",
     "tsd": "^0.15.1",
-    "typescript": "^4.2.4",
-    "typedoc": "^0.22.11"
+    "typedoc": "^0.22.11",
+    "typescript": "^4.2.4"
   },
   "type": "module",
   "scripts": {
diff --git a/src/js/tsconfig.json b/src/js/tsconfig.json
index a2a014de60b..cf0326dff36 100644
--- a/src/js/tsconfig.json
+++ b/src/js/tsconfig.json
@@ -1,7 +1,6 @@
 {
   "$schema": "http://json.schemastore.org/tsconfig",
   "compilerOptions": {
-    "declaration": true,
     "lib": ["ES2021", "DOM"],
     "outDir": "../../dist",
     "esModuleInterop": true,


Code review comments:
diff_hunk: @@ -1,6 +1,6 @@
 {
   "name": "pyodide",
-  "version": "0.20.0",
+  "version": "0.20.0-dev.0",
path: src/js/package.json
text: @user1:
```suggestion
  "version": "0.21.0-dev.0",
```

diff_hunk: @@ -79,6 +79,9 @@ node_modules/.installed : src/js/package.json src/js/package-lock.json
 dist/pyodide.js: src/js/*.ts src/js/pyproxy.gen.ts src/js/error_handling.gen.ts node_modules/.installed
 	npx rollup -c src/js/rollup.config.js
 
+dist/pyodide.d.ts: src/js/*.ts src/js/pyproxy.gen.ts src/js/error_handling.gen.ts
+	npx dts-bundle-generator -o my.d.ts pyodide.ts --export-referenced-types false
path: Makefile
text: @user1:
I guess this is a typo?

```suggestion
	npx dts-bundle-generator -o pyodide.d.ts pyodide.ts --export-referenced-types false
```

@author:
Yup thanks.