If you have a JavaScript file and you want to add rich type information to it, you can do that in a declaration file. It's like splitting your TypeScript between two files; a JavaScript file .js
with only plain JavaScript, and a declaration file .d.ts
with all the type information.
This means there is some redundancy between the files.
Commonly, if you write a TypeScript library you auto-generate the JavaScript and declaration file and package those rather than the original TypeScript. It means the library can be consumed from JavaScript and TypeScript applications and allows the consuming library to use different TypeScript version than your library.
If you have JavaScript files you want to include in compilation, you don't have to create a declaration file - IDEs allow TypeScript-style inference within JavaScript (for example, VS Code allows the // @ts-check
comment) and the compiler allows JavaScript to be included in compilation if you so wish.