Skip to content

Commit ad24a19

Browse files
committed
feat: tsconfig - references
1 parent 34b01a7 commit ad24a19

File tree

5 files changed

+99
-7
lines changed

5 files changed

+99
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# [1.0.0](https://github.com/Rain120/typescript-guide/compare/0.0.1...1.0.0) (2021-01-06)
1+
# [1.0.0](https://github.com/Rain120/typescript-guide/compare/0.0.1...1.0.0) (2021-01-09)
2+
3+
4+
### Bug Fixes
5+
6+
* what is typescript for diff with js ([34b01a7](https://github.com/Rain120/typescript-guide/commit/34b01a71712e54e05a973c4b33b68cb5ec7a0b1e))
27

38

49
### Features

docs/.vuepress/utils/alias.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"implements": "implements",
2929
"infer": "infer",
3030
"blog": "博客",
31+
"references": "tsconfig - references",
3132
"tips": "Typescript Tips",
3233
"faqs": "Typescript FAQs"
33-
}
34+
}

docs/zh/blog/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
## 博客 & 学习网站
22

33
- [TypeScript Github](https://github.com/Microsoft/TypeScript)
4-
4+
- [Typescritp tsconfig](https://www.typescriptlang.org/tsconfig)
55
- [Typescript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
6-
76
- [Typescript Playground](https://www.typescriptlang.org/play): `TypeScript` 游乐场
8-
97
- [《TypeScript Deep Dive》](https://basarat.gitbook.io/typescript/) 是一本很好的开源书, 从基础到深入, 很全面的阐述了 `TypeScript` 的各种魔法, 不管你是新手, 还是老鸟, 它都将适应你。此外, 它不同于 `TypeScript` 官方给出的文档(当然 `TypeScript` 给出的文档是很好的), 在此书中, 结合实际应用下的场景用例, 你将能更深入的理解 `TypeScript`[中文版](https://jkchao.github.io/typescript-book-chinese/)
10-
118
- [awesome-typescript](https://github.com/semlinker/awesome-typescript) 收集了很多 `Typescript` 的相关学习资料。
12-
139
- [typescript-cheatsheets-react](https://github.com/typescript-cheatsheets/react)
1410

1511
## Tips

docs/zh/compile-config/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@
9999
## 参考资料
100100

101101
[深入理解 TypeScript](https://jkchao.github.io/typescript-book-chinese/)
102+
103+
[Typescritp tsconfig](https://www.typescriptlang.org/tsconfig)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## 定义
2+
3+
`reference (引用)``TypeScript 3.0`的新特性,它支持将项目的各个部分定义为单独的`TypeScript`模块, 分割成更小的组成部分。除此之外,这允许以不同的方式配置这些模块,分别构建它们等等。
4+
5+
## 什么是项目引用
6+
7+
每个引用的`path`属性都可以指向包含 `tsconfig.json` 文件的目录,或者配置文件本身(可以有任何名称)。当你引用一个项目时:
8+
9+
- **从被引用的项目中导入模块将会加载它的输出声明文件`(.d.ts)`**
10+
- 如果引用的项目生成`outFile`,则在此项目中将显示输出文件`.d.ts`文件的声明
11+
- 如果需要,构建模式将自动构建引用的项目
12+
13+
#### Note
14+
15+
引用的工程必须启用新的`composite`设置。 这个选项用于帮助TypeScript快速确定引用工程的输出文件位置。 若启用`composite`标记则会发生如下变动:
16+
17+
- 对于`rootDir`设置,如果没有被显式指定,默认为包含`tsconfig`文件的目录
18+
- 所有的实现文件必须匹配到某个`include`模式或在`files`数组里列出。如果违反了这个限制,`tsc`会提示你哪些文件未指定。
19+
- 必须开启`declaration`选项。
20+
21+
## 作用
22+
23+
`reference` 属性作用是 **指定工程引用依赖**。通过分成多个项目,可以大大提高类型检查和编译的速度,减少使用编辑器时的内存使用,并改善对程序逻辑组的执行。
24+
25+
## 使用
26+
27+
```ts
28+
type Reference = string[] & {
29+
path: string;
30+
prepend?: Boolean;
31+
}
32+
```
33+
34+
`prepend`选项可以启用前置某个依赖的输出,前置工程会将工程的输出添加到当前工程的输出之前。它对`.js`文件和`.d.ts`文件都有效,`source map`文件也同样会正确地生成。
35+
36+
### tsconfig.json
37+
38+
```json
39+
{
40+
"references": [
41+
// ... path
42+
"some/path/which/you/want/to/set/it",
43+
]
44+
}
45+
```
46+
47+
或者这样使用
48+
49+
```json
50+
{
51+
"references": [{
52+
"path": "some/path/which/you/want/to/set/it",
53+
"prepend": true
54+
}]
55+
}
56+
```
57+
58+
## 快来耍耍啊
59+
60+
### 🌰🌰
61+
62+
<!-- 题目 -->
63+
64+
```
65+
// template
66+
```
67+
68+
### 游乐场
69+
70+
<br />
71+
72+
<Editor
73+
value='// enjoy yourself'
74+
/>
75+
76+
### 参考答案
77+
78+
```ts
79+
// answer
80+
```
81+
82+
## 参考资料
83+
84+
[Typescript Handbook Reference](https://www.typescriptlang.org/docs/handbook/project-references.html)
85+
86+
[How to use project references in TypeScript 3.0?](https://stackoverflow.com/questions/51631786/how-to-use-project-references-in-typescript-3-0)
87+
88+
[What is a Project Reference?](https://www.typescriptlang.org/docs/handbook/project-references.html#what-is-a-project-reference)

0 commit comments

Comments
 (0)