简体   繁体   中英

How to implement declaration .d.ts file in Typescript

I found a lot of literature on what the declaration .d.ts files are, but not on how to implement them. I understood that they can be auto-generated with the typescript compiler.

So my questions are:

  • when should I write the .d.ts file my own, and when should I autogenerate them?

  • what happen if I write my own .d.ts files and then also autogenerate them with the compiler?

  • should I write a .d.ts file for every .ts file or only to what I will expose as API of my library?

Thank you

If you are creating a library with TypeScript I would suggest leaving it to the TS compiler to generate the definition files. By default the compiler creates a d.ts file next to each .ts file.

Typically you would only need to hand craft a .d.ts file when you are using a library that doesn't include type definitions for example some old JavaScript library and you can't find one that someone else has created published to the DefinitelyTyped repo.

If you are writing your own I would suggest you would create a single file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM