Skip to content

Commit 4b5832d

Browse files
committed
feat: compile-config about module resolver & flie inclusive; keyword about is
1 parent be81d8e commit 4b5832d

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
### Features
1818

19+
* add Previously at keyword for descript the resource about it ([be81d8e](https://github.com/Rain120/typescript-guide/commit/be81d8e5f2f6d2892852f72143b09607ddc1d78a))
1920
* blog tips & pdfs & books ([310765f](https://github.com/Rain120/typescript-guide/commit/310765ffd4e95bcde3dc3a33c3ca7115f80d30f1))
2021
* faqs about tsconfig module target ([d40988c](https://github.com/Rain120/typescript-guide/commit/d40988c26b6c287dc72aac94a4c76b2f07cfa8cf))
2122
* faqs add interface vs type ([3bf6171](https://github.com/Rain120/typescript-guide/commit/3bf61710c8395d8ba73adfc0ae4eb7a3be0f5021))

docs/.vuepress/utils/alias.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"references": "tsconfig - references",
3434
"tsconfig-module-target": "Typescript Module Target",
3535
"interface-vs-type": "interface 和 type 有什么异同点?",
36+
"module-resolver": "Typescript 模块解析",
3637
"tips": "Typescript Tips",
3738
"faqs": "Typescript FAQs"
3839
}

docs/zh/compile-config/file-inclusion/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,26 @@
135135

136136
默认是: `false`
137137

138-
当你的编辑器中有一个 `JavaScript` 项目时, `TypeScript` 会使用`@types` 定义的 `DefinitelyTyped` 集合自动为你的节点模块提供类型。这称为自动类型获取, 您可以使用配置中的 `typeAcquisition` 对象对其进行自定义。
138+
当你的编辑器中有一个 `JavaScript` 项目时, `TypeScript` 会使用`@types` 定义的 `DefinitelyTyped` 集合自动为你的节点模块提供类型。这称为自动类型获取, 您可以使用配置中的 `typeAcquisition` 对象对其进行自定义。换句话来说就是设置自动引入库类型定义文件 `.d.ts` 相关。
139+
140+
#### 语法
141+
142+
```json
143+
{
144+
// ...
145+
"typeAcquisition": {
146+
// 是否开启自动引入库类型定义文件 .d.ts,默认为 false
147+
"enable": false,
148+
// 允许自动引入的库名,如:[ "jquery", "lodash" ]
149+
"include": ["jest"]
150+
// 排除的库名。
151+
"exclude": ["jquery"],
152+
}
153+
}
154+
155+
```
156+
157+
#### 使用
139158

140159
如果您想禁用或自定义此特性, 请创建 `jsconfig.json` 在项目的根目录中
141160

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## 定义
2+
3+
这些设置用于`TypeScript` 的模块解析。
4+
5+
## 关键字
6+
7+
### baseUrl
8+
9+
用于解析非相对模块名称的基目录。可以定义一个可以进行绝对文件解析的根文件夹。
10+
11+
```json
12+
{
13+
"compilerOptions": {
14+
"baseUrl": ".",
15+
}
16+
}
17+
```
18+
19+
### paths
20+
21+
根据 `baseUrl` 配置来告知 `TypeScript` 应如何解析 `require``import` 中的导入。
22+
23+
```json
24+
{
25+
"compilerOptions": {
26+
"baseUrl": ".",
27+
},
28+
"paths": {
29+
"src": [
30+
"./src/**"
31+
]
32+
}
33+
}
34+
```
35+
36+
### rootDirs
37+
38+
使用 `rootDirs`,可以在构建时让编译器将这个路径列表中的路径的内容都放到一个文件夹中。
39+
40+
```json
41+
{
42+
"compilerOptions": {
43+
"rootDirs": [
44+
"src/home",
45+
"src/profile",
46+
],
47+
}
48+
```
49+
50+
### typeRoots
51+
52+
用来指定默认的类型声明文件查找路径,默认为 `node_modules/@types`, 指定 `typeRoots`后,`TypeScript` 编译器会从指定的路径去引入声明文件,而不是 `node_modules/@types`, 比如以下配置会从 `typings`路径下去搜索声明:
53+
54+
```json
55+
{
56+
"compilerOptions": {
57+
"typeRoots": ["./typings"]
58+
}
59+
}
60+
```
61+
62+
### types
63+
64+
`TypeScript` 编译器会默认引入 `typeRoots` 下所有的声明文件,但是有时候我们并不希望全局引入所有定义,而是仅引入部分模块。这种情景下可以通过 `types` 指定模块名只引入我们想要的模块,比如以下只会引入 `jquery` 的声明文件:
65+
66+
```json
67+
{
68+
"compilerOptions": {
69+
"types": ["jquery"]
70+
}
71+
}
72+
```
73+
74+
## 快来耍耍啊
75+
76+
### 🌰🌰
77+
78+
<!-- 题目 -->
79+
80+
```
81+
// template
82+
```
83+
84+
### 游乐场
85+
86+
<br />
87+
88+
<Editor
89+
value='// enjoy yourself'
90+
/>
91+
92+
### 参考答案
93+
94+
```ts
95+
// answer
96+
```
97+
98+
## 参考资料
99+
100+

docs/zh/keyword/is/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function isString(value: any): boolean {
1414
`is` 关键字被称为类型谓词, 它表示是否属于某个类型, 可以有效地缩小类型范围, 它可以帮助开发者在编辑阶段发现错误,从而避免一些隐藏的运行时错误。
1515
:::
1616

17-
作用: 既可以作为返回值,也可以缩小变量的类型范围
17+
作用: 既可以作为返回值,也可以缩小变量(函数内部会校验类型)的类型范围
1818

1919
## 使用
2020

0 commit comments

Comments
 (0)