You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, this structure was rather awkward to work with if you used a single tsconfig file:
28
-
* It was possible for the implementation files to import the test files
29
-
* It wasn't possible to build `test` and `src` at the same time without having `src` appear in the output folder name, which you probably don't want
30
-
* Changing just the *internals* in the implementation files required *typechecking* the tests again, even though this wouldn't ever cause new errors
31
-
* Changing just the tests required typechecking the implementation again, even if nothing changed
30
+
31
+
* It was possible for the implementation files to import the test files
32
+
* It wasn't possible to build `test` and `src` at the same time without having `src` appear in the output folder name, which you probably don't want
33
+
* Changing just the *internals* in the implementation files required *typechecking* the tests again, even though this wouldn't ever cause new errors
34
+
* Changing just the tests required typechecking the implementation again, even if nothing changed
32
35
33
36
You could use multiple tsconfig files to solve *some* of those problems, but new ones would appear:
34
-
* There's no built-in up-to-date checking, so you end up always running `tsc` twice
35
-
* Invoking `tsc` twice incurs more startup time overhead
36
-
*`tsc -w` can't run on multiple config files at once
37
+
38
+
* There's no built-in up-to-date checking, so you end up always running `tsc` twice
39
+
* Invoking `tsc` twice incurs more startup time overhead
40
+
*`tsc -w` can't run on multiple config files at once
37
41
38
42
Project references can solve all of these problems and more.
39
43
40
44
# What is a Project Reference?
41
45
42
46
`tsconfig.json` files have a new top-level property, `references`. It's an array of objects that specifies projects to reference:
47
+
43
48
```js
44
49
{
45
50
"compilerOptions": {
@@ -54,9 +59,10 @@ Project references can solve all of these problems and more.
54
59
The `path` property of each reference can point to a directory containing a `tsconfig.json` file, or to the config file itself (which may have any name).
55
60
56
61
When you reference a project, new things happen:
57
-
* Importing modules from a referenced project will instead load its *output* declaration file (`.d.ts`)
58
-
* If the referenced project produces an `outFile`, the output file `.d.ts` file's declarations will be visible in this project
59
-
* Build mode (see below) will automatically build the referenced project if needed
62
+
63
+
* Importing modules from a referenced project will instead load its *output* declaration file (`.d.ts`)
64
+
* If the referenced project produces an `outFile`, the output file `.d.ts` file's declarations will be visible in this project
65
+
* Build mode (see below) will automatically build the referenced project if needed
60
66
61
67
By separating into multiple projects, you can greatly improve the speed of typechecking and compiling, reduce memory usage when using an editor, and improve enforcement of the logical groupings of your program.
62
68
@@ -65,9 +71,10 @@ By separating into multiple projects, you can greatly improve the speed of typec
65
71
Referenced projects must have the new `composite` setting enabled.
66
72
This setting is needed to ensure TypeScript can quickly determine where to find the outputs of the referenced project.
67
73
Enabling the `composite` flag changes a few things:
68
-
* The `rootDir` setting, if not explicitly set, defaults to the directory containing the `tsconfig` file
69
-
* All implementation files must be matched by an `include` pattern or listed in the `files` array. If this constraint is violated, `tsc` will inform you which files weren't specified
70
-
*`declaration` must be turned on
74
+
75
+
* The `rootDir` setting, if not explicitly set, defaults to the directory containing the `tsconfig` file
76
+
* All implementation files must be matched by an `include` pattern or listed in the `files` array. If this constraint is violated, `tsc` will inform you which files weren't specified
77
+
*`declaration` must be turned on
71
78
72
79
# `declarationMaps`
73
80
@@ -77,6 +84,7 @@ If you enable `--declarationMap`, you'll be able to use editor features like "Go
77
84
# `prepend` with `outFile`
78
85
79
86
You can also enable prepending the output of a dependency using the `prepend` option in a reference:
87
+
80
88
```js
81
89
"references": [
82
90
{ "path":"../utils", "prepend":true }
@@ -88,15 +96,17 @@ This works for both `.js` files and `.d.ts` files, and source map files will als
88
96
89
97
`tsc` will only ever use existing files on disk to do this process, so it's possible to create a project where a correct output file can't be generated because some project's output would be present more than once in the resulting file.
90
98
For example:
91
-
```
99
+
100
+
```txt
92
101
A
93
-
^ ^
102
+
^ ^
94
103
/ \
95
104
B C
96
105
^ ^
97
106
\ /
98
107
D
99
108
```
109
+
100
110
It's important in this situation to not prepend at each reference, because you'll end up with two copies of `A` in the output of `D` - this can lead to unexpected results.
101
111
102
112
# Caveats for Project References
@@ -116,9 +126,10 @@ In 3.0 you can use the `--build` flag with `tsc`.
116
126
This is effectively a new entry point for `tsc` that behaves more like a build orchestrator than a simple compiler.
117
127
118
128
Running `tsc --build` (`tsc -b` for short) will do the following:
119
-
* Find all referenced projects
120
-
* Detect if they are up-to-date
121
-
* Build out-of-date projects in the correct order
129
+
130
+
* Find all referenced projects
131
+
* Detect if they are up-to-date
132
+
* Build out-of-date projects in the correct order
122
133
123
134
You can provide `tsc -b` with multiple config file paths (e.g. `tsc -b src test`).
124
135
Just like `tsc -p`, specifying the config file name itself is unnecessary if it's named `tsconfig.json`.
@@ -127,7 +138,7 @@ Just like `tsc -p`, specifying the config file name itself is unnecessary if it'
127
138
128
139
You can specify any number of config files:
129
140
130
-
```
141
+
```shell
131
142
> tsc -b # Build the tsconfig.json in the current directory
132
143
> tsc -b src # Build src/tsconfig.json
133
144
> tsc -b foo/release.tsconfig.json bar # Build foo/release.tsconfig.json and bar/tsconfig.json
@@ -136,11 +147,12 @@ You can specify any number of config files:
136
147
Don't worry about ordering the files you pass on the commandline - `tsc` will re-order them if needed so that dependencies are always built first.
137
148
138
149
There are also some flags specific to `tsc -b`:
139
-
*`--verbose`: Prints out verbose logging to explain what's going on (may be combined with any other flag)
140
-
*`--dry`: Shows what would be done but doesn't actually build anything
141
-
*`--clean`: Deletes the outputs of the specified projects (may be combined with `--dry`)
142
-
*`--force`: Act as if all projects are out of date
143
-
*`--watch`: Watch mode (may not be combined with any flag except `--verbose`)
150
+
151
+
*`--verbose`: Prints out verbose logging to explain what's going on (may be combined with any other flag)
152
+
*`--dry`: Shows what would be done but doesn't actually build anything
153
+
*`--clean`: Deletes the outputs of the specified projects (may be combined with `--dry`)
154
+
*`--force`: Act as if all projects are out of date
155
+
*`--watch`: Watch mode (may not be combined with any flag except `--verbose`)
144
156
145
157
# Caveats
146
158
@@ -153,9 +165,11 @@ If you check in any build outputs (`.js`, `.d.ts`, `.d.ts.map`, etc.), you may n
153
165
# MSBuild
154
166
155
167
If you have an msbuild project, you can turn enable build mode by adding
156
-
```XML
168
+
169
+
```xml
157
170
<TypeScriptBuildMode>true</TypeScriptBuildMode>
158
171
```
172
+
159
173
to your proj file. This will enable automatic incremental build as well as cleaning.
160
174
161
175
Note that as with `tsconfig.json` / `-p`, existing TypeScript project properties will not be respected - all settings should be managed using your tsconfig file.
Copy file name to clipboardExpand all lines: pages/release notes/TypeScript 3.0.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Project Refrences
2
2
3
-
TypeScript 3.0 introduces a new concept of project references. Project references allow TypeScript projects to depend on other TypeScript projects - specifically, allowing `tsconfig.json` files to reference other `tsconfig.json` files. Specifying these dependencies makes it easier to split your code into smaller projects, since it gives TypeScript (and tools around it) a way to understand build ordering and output structure.
3
+
TypeScript 3.0 introduces a new concept of project references. Project references allow TypeScript projects to depend on other TypeScript projects - specifically, allowing `tsconfig.json` files to reference other `tsconfig.json` files. Specifying these dependencies makes it easier to split your code into smaller projects, since it gives TypeScript (and tools around it) a way to understand build ordering and output structure.
4
4
5
5
TypeScript 3.0 introduces also introducing a new mode for tsc, the `--build` flag, that works hand-in-hand with project references to enable faster TypeScript builds.
0 commit comments