]> git.ardis.lu - csvio/commitdiff
Add TypeScript declaration file (`.d.ts`) generation
authorArdis Lu <ardisglu@gmail.com>
Wed, 30 Apr 2025 05:05:31 +0000 (22:05 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 30 Apr 2025 05:05:31 +0000 (22:05 -0700)
This is the cleanest way to make a JS library importable to a TS project. This approach is similar to Svelte's approach.

Note the dev dependency on TS is only used for `.d.ts` generation. The source code itself still does not use TS (or any dependencies other than Node.js) at all.

.gitignore [new file with mode: 0644]
package.json

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..1d75092
--- /dev/null
@@ -0,0 +1,2 @@
+node_modules
+types
\ No newline at end of file
index a986620b8e9bf4840cad0d08a6d7ca7834d69eab..36dfb7fca0c6ba2f1d74927c2df1169bf6faa1a0 100644 (file)
     "node": ">=20"
   },
   "files": [
-    "src/*"
+    "./types/*",
+    "./src/*"
   ],
-  "exports": "./src/index.js",
+  "exports": {
+    ".": {
+      "types": "./types/index.d.ts",
+      "default": "./src/index.js"
+    }
+  },
   "scripts": {
+    "types": "tsc ./src/index.js --allowJs --declaration --emitDeclarationOnly --declarationMap --outFile ./types/index.d.ts",
     "test": "node --test --test-skip-pattern=\"/^large:/\"",
     "test:large": "node --test --test-name-pattern=\"/^large:/\"",
     "test:coverage": "npm run test -- --experimental-test-coverage",
     "bench": "node ./benchmark/core.bench.js"
+  },
+  "devDependencies": {
+    "typescript": "^5.8.3"
   }
 }
This page took 0.055191 seconds and 4 git commands to generate.