-
Notifications
You must be signed in to change notification settings - Fork 130
i18n: tsconfig-reference top-level options to zh #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
635c4d8
f4388bc
17feb91
22d8d82
c3aa684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,18 @@ | ||||||
## TSConfig 前言 | ||||||
--- | ||||||
header: TSConfig 介绍 | ||||||
firstLine: TSConfig 文件象征着,它所在的目录是一个 TypeScript 项目或者 JavaScript 项目的根目录... | ||||||
--- | ||||||
|
||||||
目录中的 TSConfig 文件表明该目录是 TypeScript 或 JavaScript 项目的根目录。 | ||||||
TSConfig 文件可以是 `tsconfig.json` 或 `jsconfig.json`,它们的配置项和行为相同。 | ||||||
|
||||||
此页涵盖了 TSConfig 文件中可用的所有不同选项。本页从每个选项的概述开始,到 JSON 文件的根属性,然后是`compilerOptions`(大部分选项),最后是 `watchOptions`。 | ||||||
TSConfig 文件象征着,它所在的目录是一个 TypeScript 项目或者 JavaScript 项目的根目录。 | ||||||
TSConfig 文件可以是 `tsconfig.json` 或 `jsconfig.json`,它们的配置相同。 | ||||||
|
||||||
此页涵盖了 TSConfig 文件中可用的所有不同选项。同时没有按照线性叙述来构建,而是分为了5个主要部分: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- 一个配置项的分类概览 | ||||||
- [root fields](#Project_Files_0): 告知 TypeScript 哪些文件需要被处理 | ||||||
- [`compilerOptions`](#compilerOptions): 本页的主要内容 | ||||||
- [`watchOptions`](#watchOptions): 配置监听模式 | ||||||
- [`typeAcquisition`](#typeAcquisition): 配置 JavaScript 项目使用类型的方式 | ||||||
|
||||||
如果你是从零开始 TSConfig,可以考虑使用 `tsc --init` 或者 [TSConfig base](https://github.com/tsconfig/bases#centralized-recommendations-for-tsconfig-bases) 来进行配置。 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||
--- | ||||||
display: "Exclude" | ||||||
oneline: "过滤 [`include`](#include) 选项。" | ||||||
--- | ||||||
|
||||||
在解析 [`include`](#include) 选项时,需要跳过的文件名称或文件匹配器的列表。 | ||||||
|
||||||
**Important**: `exclude` _仅仅_ 改变 [`include`](#include) 选项包含的文件。 | ||||||
`exclude` 指定的文件可能仍然是你代码的一部分,由于 被 `import` 引入到你的代码中,或者被 `types` 包含,或者使用 `/// <reference` 引入,或者包含在 [`files`](#files) 中。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
它不是一种 **阻止** 文件被包含在代码库中的机制-它只是改变 [`include`](#include) 配置项查找的内容。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
--- | ||||||
display: "Extends" | ||||||
oneline: "指定一个路径或者 node 模块引用用于配置继承" | ||||||
--- | ||||||
|
||||||
`extends` 的值是要继承的配置文件的路径。 | ||||||
路径可以使用 POSIX 风格(Linux MacOS) 或者 Windows 风格(路径中的 `\` 需要转义)。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
TSConfig 中的配置会覆盖继承的配置。 相对路径计算是以其所在配置文件为基准,不受继承影响。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
注意: [`files`](#files),[`include`](#include) 和 `exclude` 会覆盖继承的配置,配置文件不允许循环继承。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
[`references`](#references) 是唯一不被继承的顶级配置项。 | ||||||
|
||||||
##### Example | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
`configs/base.json`: | ||||||
|
||||||
```json tsconfig | ||||||
{ | ||||||
"compilerOptions": { | ||||||
"noImplicitAny": true, | ||||||
"strictNullChecks": true | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
`tsconfig.json`: | ||||||
|
||||||
```json tsconfig | ||||||
{ | ||||||
"extends": "./configs/base", | ||||||
"files": ["main.ts", "supplemental.ts"] | ||||||
} | ||||||
``` | ||||||
|
||||||
`tsconfig.nostrictnull.json`: | ||||||
|
||||||
```json tsconfig | ||||||
{ | ||||||
"extends": "./tsconfig", | ||||||
"compilerOptions": { | ||||||
"strictNullChecks": false | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
可配置相对路径的配置项,相对路径计算是以该配置项所在配置文件为基准,不受继承影响。 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||
--- | ||||||
display: "Files" | ||||||
oneline: "一个数组,每一项是项目所需包含文件的路径。和 [`include`](#include) 不同的是, files 不支持路径匹配。" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--- | ||||||
|
||||||
明确指出项目所需包含的文件。如果找不到任何能包含的文件,会报错。 | ||||||
|
||||||
```json tsconfig | ||||||
{ | ||||||
"compilerOptions": {}, | ||||||
"files": [ | ||||||
"core.ts", | ||||||
"sys.ts", | ||||||
"types.ts", | ||||||
"scanner.ts", | ||||||
"parser.ts", | ||||||
"utilities.ts", | ||||||
"binder.ts", | ||||||
"checker.ts", | ||||||
"tsc.ts" | ||||||
] | ||||||
} | ||||||
``` | ||||||
|
||||||
这个配置在文件数量比较小并且不需要引用一些全局文件的时候很有用。 | ||||||
也可以使用 [`include`](#include) 实现更多配置能力。 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,66 @@ | ||||||
--- | ||||||
display: "Include" | ||||||
oneline: "要进行编译的文件的路径或匹配器的列表。" | ||||||
--- | ||||||
|
||||||
指明程序所包含的文件名称或文件匹配器。 | ||||||
他们相对于 `tsconfig.json` 所在的目录进行解析。 | ||||||
|
||||||
```json | ||||||
{ | ||||||
"include": ["src/**/*", "tests/**/*"] | ||||||
} | ||||||
``` | ||||||
|
||||||
包含的文件: | ||||||
|
||||||
<!-- TODO: #135 | ||||||
```diff | ||||||
. | ||||||
- ├── scripts | ||||||
- │ ├── lint.ts | ||||||
- │ ├── update_deps.ts | ||||||
- │ └── utils.ts | ||||||
+ ├── src | ||||||
+ │ ├── client | ||||||
+ │ │ ├── index.ts | ||||||
+ │ │ └── utils.ts | ||||||
+ │ ├── server | ||||||
+ │ │ └── index.ts | ||||||
+ ├── tests | ||||||
+ │ ├── app.test.ts | ||||||
+ │ ├── utils.ts | ||||||
+ │ └── tests.d.ts | ||||||
- ├── package.json | ||||||
- ├── tsconfig.json | ||||||
- └── yarn.lock | ||||||
``` --> | ||||||
|
||||||
``` | ||||||
. | ||||||
├── scripts ⨯ | ||||||
│ ├── lint.ts ⨯ | ||||||
│ ├── update_deps.ts ⨯ | ||||||
│ └── utils.ts ⨯ | ||||||
├── src ✓ | ||||||
│ ├── client ✓ | ||||||
│ │ ├── index.ts ✓ | ||||||
│ │ └── utils.ts ✓ | ||||||
│ ├── server ✓ | ||||||
│ │ └── index.ts ✓ | ||||||
├── tests ✓ | ||||||
│ ├── app.test.ts ✓ | ||||||
│ ├── utils.ts ✓ | ||||||
│ └── tests.d.ts ✓ | ||||||
├── package.json | ||||||
├── tsconfig.json | ||||||
└── yarn.lock | ||||||
``` | ||||||
|
||||||
`include` 和 `exclude` 匹配器支持的匹配符: | ||||||
|
||||||
- `*` 匹配零个或多个字符 (不包含目录分割符) | ||||||
- `?` 匹配任何一个字符 (不包含目录分割符) | ||||||
- `**/` 匹配任何深度的目录 | ||||||
|
||||||
如果匹配器不包含文件拓展名只,支持特定拓展名的文件。默认支持 `.ts`, `.tsx`和 `.d.ts`,如果开启了 [`allowJs`](#allowJs),额外支持 `.js` 和 `.jsx`。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.