Skip to content

Tsconfig zh #1268

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

Merged
merged 8 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
display: "Allow Umd Global Access"
oneline: "Assume UMD imports are all globally available"
display: "允许 Umd 全局使用"
oneline: "假设 UMD 的导入是全局可用的"
---

When set to true, `allowUmdGlobalAccess` lets you access UMD exports as globals from inside module files. A module file is a file that has imports and/or exports. Without this flag, using an export from a UMD module requires an import declaration.
当 `allowUmdGlobalAccess` 设置为 true 时,将允许你在模块文件中以全局变量的形式使用 UMD 的导出。
模块文件是具有或同时导入、导出的文件。当未设置这个选项时,使用 UMD 模块的导出需要首先导入声明。

An example use case for this flag would be a web project where you know the particular library (like jQuery or Lodash) will always be available at runtime, but you can’t access it with an import.
一个典型场景是:在一个 Web 项目中, 您知道特定的库(如 jQuery Lodash )在运行时总是可用的,但您不能在通过导入来使用他们。
13 changes: 6 additions & 7 deletions packages/tsconfig-reference/copy/zh/options/baseUrl.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
display: "Base Url"
oneline: "Set a baseurl for relative module names"
display: "基准目录"
oneline: "为相对路径的模块名设置基准目录"
---

Lets you set a base directory to resolve non-absolute module names.
可以让您设置解析非绝对路径模块名时的基准目录。

You can define a root folder where you can do absolute file resolution. E.g.
你可以定义一个根目录,以进行绝对路径文件解析。例如:

```
baseUrl
Expand All @@ -15,13 +15,12 @@ baseUrl
└── tsconfig.json
```

With `"baseUrl": "./"` inside this project TypeScript will look for files starting at the same folder as the `tsconfig.json`.
在这个项目中被配置为 `"baseUrl": "./"`TypeScript 将会从首先寻找与 `tsconfig.json` 处于相同目录的文件。

```ts
import { helloWorld } from "hello/world";

console.log(helloWorld);
```

If you get tired of imports always looking like `"../"` or `"./"`. Or needing
to change as you move files, this is a great way to fix that.
当你厌倦了导入文件时总是 `"../"` 或 `"./"`,或需要在移动文件时更改路径,这是一个很好的解决方法。
10 changes: 5 additions & 5 deletions packages/tsconfig-reference/copy/zh/options/moduleResolution.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
display: "Module Resolution"
oneline: "Allow TypeScript 1.6 module resolution strategies"
display: "模块解析"
oneline: "允许 TypeScript 1.6 的模块解析策略"
---

Specify the module resolution strategy: `'node'` (Node.js) or `'classic'` (used in TypeScript before the release of 1.6).
You probably won't need to use `classic` in modern code.
指定模块解析策略:`'node'` Node.js) 或 `'classic'` (在 TypeScript 1.6 版本之前使用)。
你可能不需要在新代码中使用 `classic`

There is a handbook reference page on [Module Resolution](/docs/handbook/module-resolution.html)
这里有一个关于[模块解析](/docs/handbook/module-resolution.html)的手册参考。
14 changes: 7 additions & 7 deletions packages/tsconfig-reference/copy/zh/options/paths.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
display: "Paths"
oneline: "A set of locations to look for imports in"
display: "路径设置"
oneline: "一组用于寻找模块导入的路径"
---

A series of entries which re-map imports to lookup locations relative to the `baseUrl`, there is a larger coverage of `paths` in [the handbook](/docs/handbook/module-resolution.html#path-mapping).
一些将模块导入重新映射到相对于 `baseUrl` 路径的配置。[手册](/docs/handbook/module-resolution.html#path-mapping)中有更多关于 `paths` 的内容。

`paths` lets you declare how TypeScript should resolve an import in your `require`/`import`s.
`paths` 可以允许你声明 TypeScript 应该如何解析你的 `require`/`import`

```json tsconfig
{
Expand All @@ -18,7 +18,7 @@ A series of entries which re-map imports to lookup locations relative to the `ba
}
```

This would allow you to be able to write `import "jquery"`, and get all of the correct typing locally.
这将使你可以写 `import "jquery"`,并且在本地获得所有正确的类型。

```json tsconfig
{
Expand All @@ -35,5 +35,5 @@ This would allow you to be able to write `import "jquery"`, and get all of the c
}
```

In this case, you can tell the TypeScript file resolver to support a number of custom prefixes to find code.
This pattern can be used to avoid long relative paths within your codebase.
这种情况下,你可以告诉 TypeScript 文件解析器支持一些自定义的前缀来寻找代码。
这种模式可以避免在你的代码中出现过长的相对路径。
10 changes: 5 additions & 5 deletions packages/tsconfig-reference/copy/zh/options/preserveSymlinks.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
display: "Preserve Symlinks"
oneline: "Do not resolve symlink paths"
display: "保留符号链接"
oneline: "不解析符号链接路径"
---

This is to reflect the same flag in Node.js; which does not resolve the real path of symlinks.
这是为了匹配 Node.js 中相同的选项,它不解析符号链接的真实路径。

This flag also exhibits the opposite behavior to Webpack’s `resolve.symlinks` option (i.e. setting TypeScript’s `preserveSymlinks` to true parallels setting Webpack’s `resolve.symlinks` to false, and vice-versa).
这个选项也表现出与 Webpack`resolve.symlinks` 选项相反的行为(即设置 TypeScript`preserveSymlinks` true, 与之对应的 Webpack`resolve.symlinks` false。反之亦然)

With this enabled, references to modules and packages (e.g. `import`s and `/// <reference type="..." />` directives) are all resolved relative to the location of the symbolic link file, rather than relative to the path that the symbolic link resolves to.
启用后,对于模块和包的引用(例如 `import` `/// <reference type="..." />` 指令都相对于符号链接所在的位置进行解析,而不是相对于符号链接解析后的路径。
12 changes: 5 additions & 7 deletions packages/tsconfig-reference/copy/zh/options/rootDirs.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
display: "Root Dirs"
oneline: "Set multiple root directories"
display: "根目录"
oneline: "设置多个根目录"
---

Using `rootDirs`, you can inform the compiler that there are many "virtual" directories acting as a single root.
This allows the compiler to resolve relative module imports within these "virtual" directories, as if they were merged in to one directory.
通过 `rootDirs`,你可以告诉编译器有许多“虚拟”的目录作为一个根目录。这将会允许编译器在这些“虚拟”目录中解析相对应的模块导入,就像它们被合并到同一目录中一样。

For example:
例如:

```
src
Expand All @@ -28,5 +27,4 @@ For example:
}
```

This does not affect how TypeScript emits JavaScript, it only emulates the assumption that they will be able to
work via those relative paths at runtime.
这不会影响到 TypeScript 如何生成 JavaScript,而仅是模拟了假设它们在运行时能通过这些相对路径工作。
15 changes: 7 additions & 8 deletions packages/tsconfig-reference/copy/zh/options/typeRoots.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
display: "Type Roots"
oneline: "locations where TypeScript should look for type definitions"
display: "类型根路径"
oneline: "TypeScript 应该去哪些路径寻找类型定义"
---

By default all _visible_ "`@types`" packages are included in your compilation.
Packages in `node_modules/@types` of any enclosing folder are considered _visible_.
For example, that means packages within `./node_modules/@types/`, `../node_modules/@types/`, `../../node_modules/@types/`, and so on.
默认情况下,所有 _可见_ 的 "`@types`" 包都将包含在你的编译过程中。
`node_modules/@types` 中的任何包都被认为是 _可见_ 的。
例如,这意味着包含 `./node_modules/@types/``../node_modules/@types/``../../node_modules/@types/` 中所有的包。

If `typeRoots` is specified, _only_ packages under `typeRoots` will be included. For example:
`typeRoots` 被指定,_仅有_ 在 `typeRoots` 下的包会被包含。例如:

```json tsconfig
{
Expand All @@ -17,5 +17,4 @@ If `typeRoots` is specified, _only_ packages under `typeRoots` will be included.
}
```

This config file will include _all_ packages under `./typings` and `./vendor/types`, and no packages from `./node_modules/@types`.
All paths are relative to the `tsconfig.json`.
这个配置文件将包含 `./typings` 和 `./vendor/types` 下的所有包,而不包括 `./node_modules/@types` 下的。其中所有的路径都是相对于 `tsconfig.json`。
31 changes: 15 additions & 16 deletions packages/tsconfig-reference/copy/zh/options/types.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
display: "Types"
oneline: "Used to create an allowlist of types to be included in the compile"
display: "类型"
oneline: "用于创建一个允许包含在编译过程中的类型列表"
---

By default all _visible_ "`@types`" packages are included in your compilation.
Packages in `node_modules/@types` of any enclosing folder are considered _visible_.
For example, that means packages within `./node_modules/@types/`, `../node_modules/@types/`, `../../node_modules/@types/`, and so on.
默认情况下,所有 _可见_ 的 "`@types`" 包都将包含在你的编译过程中。
`node_modules/@types` 中的任何包都被认为是 _可见_ 的。
例如,这意味着包含 `./node_modules/@types/``../node_modules/@types/``../../node_modules/@types/` 中所有的包。。

If `types` is specified, only packages listed will be included in the global scope. For instance:
`types` 被指定,则只有列出的包才会被包含在全局范围内。例如:

```json tsconfig
{
Expand All @@ -17,24 +17,23 @@ If `types` is specified, only packages listed will be included in the global sco
}
```

This `tsconfig.json` file will _only_ include `./node_modules/@types/node`, `./node_modules/@types/jest` and `./node_modules/@types/express`.
Other packages under `node_modules/@types/*` will not be included.
这个 `tsconfig.json` 文件将 _只会_ 包含 `./node_modules/@types/node``./node_modules/@types/jest` `./node_modules/@types/express`
其他在 `node_modules/@types/*` 下的包将不会被包含。

### What does this affect?
### 这会影响什么?

This option does not affect how `@types/*` are included in your application code, for example if you had the above `compilerOptions` example with code like:
此选项不会影响 `@types/*` 如何被包含在你的代码中,例如你在有上面例子里 `compilerOptions` 的环境中写了这样的代码:

```ts
import * as moment from "moment";

moment().format("MMMM Do YYYY, h:mm:ss a");
```

The `moment` import would be fully typed.
`moment` 导入会有完整的类型。

When you have this option set, by not including a module in the `types` array it:
当你设置了这个选项,通过不在 `types` 数组中包含,它将:
- 不会再你的项目中添加全局声明(例如 node 中的 `process` 或 Jest 中的 `expect`)
- 导出不会出现再自动导入的建议中

- Will not add globals to your project (e.g `process` in node, or `expect` in Jest)
- Will not have exports appear as auto-import recommendations

This feature differs from [`typeRoots`](#typeRoots) in that it is about specifying only the exact types you want included, whereas [`typeRoots`](#typeRoots) supports saying you want particular folders.
此功能与 [`类型根路径`](#typeRoots) 不同的是,它只指定你想要包含的具体类型,而 [`类型根路径`](#typeRoots) 支持你想要特定的文件夹。