[TypeScript] Build output single JavaScript file (. js) with Declaration archive (. D.ts) Problem Scenario
Developers use Visual Studio to develop Typescript, which makes it easy to quickly compile all of the typescript files (. ts) in the project into JavaScript files (. js) for use in HTML pages. But when software projects become more and more large, too many. js file references increase the burden of developing. html files, and the dependencies between each. js file are also easily caused by the error in the reference order, which can cause unexpected problems.
<!DOCTYPE html>
Solution: Build output single JavaScript file (. js)In order to solve the problems caused by multiple. js file references, Visual Studio provides the built-in output settings for the "Combine JavaScript output into file" in the Typescript build Settings page. Developers simply tick this setting, and after the project is compiled, Visual Studio automatically merges all the. JS content generated in the project into a single. js file to output, making it easy for other HTML developers to use.
<!DOCTYPE html>
Solution: Build output single declaration profile (. D.ts)Once the "combine JavaScript output into file" is checked, the developer can make the. TS outputs in the project a single. js file for use by other developers. At this point, if other developers expect to be able to use typescript syntax for follow-up development, we can choose to provide a single. js file for project output, plus a corresponding declaration file (. d.ts) In addition to the option to provide the. TS source file directly. To be available to other developers.
In Visual Studio, to build the. d.ts file for project output, developers can check the "Generate declaration files" setting in the Typescript build Settings page to set the output settings. Later, when the project is compiled, Visual studio automatically builds the. js file that is output in the project, creating the corresponding. d.ts file, which is convenient for developers to use with other typescript developers.
[TypeScript] Build output single JavaScript file (. js) with declaration file (. d.ts)