From: Ardis Lu Date: Wed, 30 Apr 2025 05:05:31 +0000 (-0700) Subject: Add TypeScript declaration file (`.d.ts`) generation X-Git-Tag: v0.1.0~23 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=66164961f4bf5df5b49652f09509c6f62ed7d4e8;p=csvio Add TypeScript declaration file (`.d.ts`) generation 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. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d75092 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +types \ No newline at end of file diff --git a/package.json b/package.json index a986620..36dfb7f 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,23 @@ "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" } }