Issue
I have a TypeScript library that I want to export for other JS/TS developers to use. As a benefit for users of my library, I'd like to export the types as well. How do I do that? I.e. how do I export a index.d.ts
type declaration file?
I've looked at the TypeScript docs, but they seem to talk about writing explicit type declarations, whereas I want to automatically export type declarations when running npx tsc
.
Here's the tsconfig.json
:
{
"compilerOptions": {
"lib": ["ES2019"],
"module": "es6",
"target": "es5",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"outDir": "build",
"strict": true,
"noImplicitAny": true,
},
"include": ["./**/*.ts"],
"exclude": ["node_modules", ".vscode", "test"]
}
Solution
Sometimes writing out a question tells you how to find the answer yourself :)
Adding --declaration
as specified in the CLI docs does the trick, i.e.:
tsc index.js --declaration
Answered By - pir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.