Skip to content

Commit 5255471

Browse files
erikras-gilfoyle-agentErik Rasmussen
andauthored
Add TypeScript declaration files to published package (#43)
* Add TypeScript declaration files to published package PROBLEM: The package has TypeScript source files but does not publish .d.ts declaration files to npm. Users get no type information when installing from npm. SOLUTION: 1. Add 'typings' field to package.json pointing to dist/index.d.ts 2. Add copyTypes script to package-scripts.js to generate declarations 3. Include copyTypes in build.default series PATTERN: Matches the approach used in final-form-calculate, final-form-submit-listener, and other packages in the final-form ecosystem. Fixes: Issue #47 pattern (TypeScript declarations not in published package) * Fix copyTypes script description - it generates, not copies --------- Co-authored-by: Erik Rasmussen <erik@mini.local>
1 parent f721d73 commit 5255471

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

package-scripts.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
},
1818
build: {
1919
description: 'delete the dist directory and run all builds',
20-
default: series(rimraf('dist'), 'nps build.rollup'),
20+
default: series(rimraf('dist'), 'nps build.rollup', 'nps copyTypes'),
2121
rollup: {
2222
description: 'Run all rollup builds sequentially',
2323
default: series.nps(
@@ -49,6 +49,10 @@ export default {
4949
},
5050
andTest: series.nps('build', 'test.size')
5151
},
52+
copyTypes: {
53+
description: 'Generate TypeScript declaration files to dist',
54+
script: 'tsc --declaration --emitDeclarationOnly --outDir dist'
55+
},
5256
docs: {
5357
description: 'Generates table of contents in README',
5458
script: 'doctoc README.md'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"jsnext:main": "dist/final-form-focus.es.js",
77
"module": "dist/final-form-focus.es.js",
88
"type": "module",
9+
"typings": "dist/index.d.ts",
910
"files": [
1011
"dist"
1112
],

0 commit comments

Comments
 (0)