I am building a react library in typescript and i want to provide consumers of this library a typescript definition file.
How do i make sure the typescript definition file is always correct an matching the js code?
Or if my components are written in typescript is there a way to generate a single d.ts file from all the generated d.ts files the compiler generated for me?
If you are the author of the library, it's extremely easy to provide and maintain the definitions. It works the same way regardless of the library you're using (such as React).
You can create a
.d.ts file by passing
-d to compiler arguments or adding
declaration: true in your
Add field named
typings to your
"typings": "./index.d.ts" (
./index.d.ts is actually the default value if
typings is omitted).
TypeScript compiler will automatically use provided typings if the user installs your library via NPM.