If we enable sourcemap which allows us to debug on the browser. Likewise looking for the use case of declaration and declarationMap.
I have searched over the internet, but my bad could not found the actual use case except generating .d.ts file.
Generating .d.ts
files is exactly the use case for declaration
compiler option, so the build output is .js
, while all type definitions can be still preserved for other TS projects consuming your project.
The IDE can make use of declarationMap
option to provide better developer experience: It enables you to quickly navigate to the original sources, when you currently have a corresponding .d.ts
file open and want to see its implementation (see also this answer).
Enabling --declarationMap alongside --declaration causes the compiler to emit .d.ts.map files alongside the output .d.ts files. Language Services can also now understand these map files, and uses them to map declaration-file based definition locations to their original source, when available.
In other words, hitting go-to-definition on a declaration from a .d.ts file generated with --declarationMap will take you to the source file (.ts) location where that declaration was defined, and not to the .d.ts.