- Learn React with TypeScript 3
- Carl Rippon
- 230字
- 2021-06-10 19:16:44
Additions to compiler options
Just referencing another project isn't enough for the TypeScript compiler to properly handle multiple projects. We need to add some additional compiler options in the dependent project.
The compilerOptions field has a new field called composite, which must be set to true if we are using multiple projects. This ensures certain options are enabled so that this project can be referenced and built incrementally for any project that depends on it.
When composite is true, declaration must also be set to true, forcing the corresponding .d.ts file to be generated, containing the project's types. This allows TypeScript to only build dependent projects when types are changed and not rebuild all the dependent projects all the time.
Let's make the following changes to our working example:
- Let's open up tsconfig.json in the Shared project and make the following changes:
{
"compilerOptions": {
"composite": true,
"declaration": true,
...
},
}
- In the terminal, let's go to the Shared project directory and compile our Shared project:
cd ..
cd Shared
tsc
The project compiles okay. Let's now try to compile ProjectA again in the terminal:
cd ..
cd ProjectA
tsc
This time, ProjectA compiles just fine.
So, we have successfully tied together two projects using TypeScript 3's multiple projects feature. In the next section, we'll improve the setup of our projects even more.
- C# 7 and .NET Core Cookbook
- 嵌入式軟件系統測試:基于形式化方法的自動化測試解決方案
- Pandas Cookbook
- Rust編程從入門到實戰
- 技術領導力:程序員如何才能帶團隊
- Java編程技術與項目實戰(第2版)
- Mastering Android Development with Kotlin
- Learning OpenCV 3 Computer Vision with Python(Second Edition)
- UNIX Linux程序設計教程
- HoloLens與混合現實開發
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- Mastering Apache Storm
- Java Web開發實例大全(基礎卷) (軟件工程師開發大系)
- C++程序設計教程
- Node.js區塊鏈開發