TypeScript-Handbook
TypeScript-Handbook copied to clipboard
Explain how to fix type declarations that are out of date
The handbook contains some decent attempts at explaining how one can write a .d.ts file for an already existing npm package.
However it is quite common to find that some attribute is missing from some interface (let's say a new attribute to some configuration) inside one of these declarations. In that case it would be easiest to be able to use declaration merging to fix that temporarily in your own project while you maybe open an issue or PR for DefinitelyTyped.
Unfortunately this use case is not explained very well in the guide book and it becomes a painful process of trial and error to find the right incantation of keywords to be able to reference the declared piece that you want to augment.
- Should you do it through a .ts or .d.ts file?
- Do you have to reference the declaration through an
import "something"or a<reference types="something"/>? - Do we use declare in .d.ts or no declare in a .ts file?
- Do we use a module or namespace?
- Is
declare globalsomehow necessary?