根字段
¥Root Fields
启动是 TSConfig 中的根选项 - 这些选项与你的 TypeScript 或 JavaScript 项目的设置方式有关。
¥Starting up are the root options in the TSConfig - these options relate to how your TypeScript or JavaScript project is set up.
# 文件 - files
指定要包含在程序中的文件的允许列表。如果找不到任何文件,则会发生错误。
¥Specifies an allowlist of files to include in the program. An error occurs if any of the files can’t be found.
{" ": {}," ": ["core.ts","sys.ts","types.ts","scanner.ts","parser.ts","utilities.ts","binder.ts","checker.ts","tsc.ts"]}
当你只有少量文件并且不需要使用 glob 来引用许多文件时,这很有用。如果你需要它,请使用 include
。
¥This is useful when you only have a small number of files and don’t need to use a glob to reference many files.
If you need that then use include
.
# 扩展 - extends
extends
的值是一个字符串,其中包含要继承的另一个配置文件的路径。路径可以使用 Node.js 样式解析。
¥The value of extends
is a string which contains a path to another configuration file to inherit from.
The path may use Node.js style resolution.
首先加载来自基础文件的配置,然后由继承配置文件中的配置覆盖。配置文件中找到的所有相对路径都将相对于它们起源的配置文件进行解析。
¥The configuration from the base file are loaded first, then overridden by those in the inheriting config file. All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.
值得注意的是,继承配置文件中的 files
、include
和 exclude
会覆盖基本配置文件中的 files
、include
和 exclude
,并且不允许配置文件之间的循环。
¥It’s worth noting that files
, include
, and exclude
from the inheriting config file overwrite those from the
base config file, and that circularity between configuration files is not allowed.
目前,唯一从继承中排除的顶层属性是 references
。
¥Currently, the only top-level property that is excluded from inheritance is references
.
示例
¥Example
configs/base.json
:
{" ": {" ": true," ": true}}
tsconfig.json
:
{" ": "./configs/base"," ": ["main.ts", "supplemental.ts"]}
tsconfig.nostrictnull.json
:
{" ": "./tsconfig"," ": {" ": false}}
在配置文件中找到的具有相对路径的属性(未从继承中排除)将相对于它们起源的配置文件进行解析。
¥Properties with relative paths found in the configuration file, which aren’t excluded from inheritance, will be resolved relative to the configuration file they originated in.
- 默认:
false
- 版本:
# 包括 - include
指定要包含在程序中的文件名或模式数组。这些文件名是相对于包含 tsconfig.json
文件的目录解析的。
¥Specifies an array of filenames or patterns to include in the program.
These filenames are resolved relative to the directory containing the tsconfig.json
file.
json
{"include": ["src/**/*", "tests/**/*"]}
将包括:
¥Which would include:
.├── 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
支持通配符来制作 glob 模式:
¥include
and exclude
support wildcard characters to make glob patterns:
-
*
匹配零个或多个字符(不包括目录分隔符)¥
*
matches zero or more characters (excluding directory separators) -
?
匹配任何一个字符(不包括目录分隔符)¥
?
matches any one character (excluding directory separators) -
**/
匹配嵌套到任何级别的任何目录¥
**/
matches any directory nested to any level
如果模式中的最后一个路径段不包含文件扩展名或通配符,则将其视为目录,并包含该目录内具有受支持扩展名的文件(例如,默认情况下为 .ts
、.tsx
和 .d.ts
,如果 allowJs
设置为 true,则为 .js
和 .jsx
)。
¥If the last path segment in a pattern does not contain a file extension or wildcard character, then it is treated as a directory, and files with supported extensions inside that directory are included (e.g. .ts
, .tsx
, and .d.ts
by default, with .js
and .jsx
if allowJs
is set to true).
# 排除 - exclude
指定在解析 include
时应跳过的文件名或模式数组。
¥Specifies an array of filenames or patterns that should be skipped when resolving include
.
重要:exclude
仅更改由于 include
设置而包含的文件。由于代码中的 import
语句、types
包含、/// <reference
指令或在 files
列表中指定,exclude
指定的文件仍然可以成为代码库的一部分。
¥Important: exclude
only changes which files are included as a result of the include
setting.
A file specified by exclude
can still become part of your codebase due to an import
statement in your code, a types
inclusion, a /// <reference
directive, or being specified in the files
list.
它不是一种防止文件被包含在代码库中的机制 - 它只是更改 include
设置找到的内容。
¥It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include
setting finds.
# 参考 - references
项目引用是一种将 TypeScript 程序结构化为较小部分的方法。使用项目引用可以大大改善构建和编辑器交互时间,强制组件之间的逻辑分离,并以新的和改进的方式组织代码。
¥Project references are a way to structure your TypeScript programs into smaller pieces. Using Project References can greatly improve build and editor interaction times, enforce logical separation between components, and organize your code in new and improved ways.
你可以在手册的 项目引用 部分中阅读有关引用如何工作的更多信息
¥You can read more about how references works in the Project References section of the handbook
- 默认:
false