diff --git a/docs/typescript.html b/docs/typescript.html index cb85d3a2..cce80c78 100644 --- a/docs/typescript.html +++ b/docs/typescript.html @@ -42,7 +42,7 @@

包含最重要基础、泛型、方法、class 等 TypeScript 强类型编程语言语法的快速参考备忘单。初学者的完整快速参考。

入门 Interface

+

入门 Interface

介绍

TypeScript 是具有类型语法的 JavaScript。Interface 是为了匹配它们的运行时行为而构建的。

    @@ -1004,16 +1004,677 @@ }

从数组中提取类型

-
type Point = { x: number; y: number; }
+
type Point = { x: number; y: number; }
 type Data = Point[];
 // Data 是个数组,提取里面的元素类型
 type PointDetail = Data[number];
 // type PointDetail = { x: number; y: number; }
 
+

只读元组类型

const point = [3, 4] as const
 // type 'readonly [3, 4]'
 
+

TSConfig Ref

+

顶层配置

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
files #指定要包含在程序中的文件的允许列表
extends #包含要继承的另一个配置文件的路径
include #指定要包含在程序中的文件名或模式数组
exclude #指定解析包含时应跳过的文件名或模式数组
references #项目引用是一种将 TypeScript 程序构造成更小部分的方法
+ +
+
{
+  "extends": "./tsconfig",
+  "compilerOptions": {
+    "strictNullChecks": false
+  }
+}
+
+

类型检查(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
allowUnreachableCode #允许无法访问的代码
allowUnusedLabels #允许未使用的标签
alwaysStrict #始终严格
exactOptionalPropertyTypes #启用后,TypeScript 应用更严格的规则来处理它如何处理类型或具有 ? 字首
noFallthroughCasesInSwitch #在 switch 语句中报告失败案例的错误
noImplicitAny #在某些不存在类型注释的情况下,TypeScript 将在无法推断类型时回退到变量的任何类型
noImplicitOverride #当处理使用继承的类时,子类可能与在基类中重命名时重载的函数“不同步”
noImplicitReturns #没有隐式返回
noImplicitThis #使用隐含的“any”类型在“this”表达式上引发错误
noPropertyAccessFromIndexSignature #此设置确保通过“点”(obj.key)语法访问字段和“索引”(obj[“key”])以及在类型中声明属性的方式之间的一致性
noUncheckedIndexedAccess #TypeScript 有一种方法可以通过索引签名来描述对象上具有未知键但已知值的对象
noUnusedLocals #报告未使用的局部变量的错误
noUnusedParameters #报告函数中未使用参数的错误
strict #严格标志启用了范围广泛的类型检查行为,从而更有效地保证了程序的正确性
strictBindCallApply #TypeScript 将检查函数调用、绑定和应用的内置方法是否使用底层函数的正确参数调用
strictFunctionTypes #此标志会导致更正确地检查函数参数
strictNullChecks #严格的空检查
strictPropertyInitialization #严格的属性初始化
useUnknownInCatchVariables #在 TypeScript 4.0 中,添加了支持以允许将 catch 子句中的变量类型从 any 更改为 unknown
+ +

模块(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
allowUmdGlobalAccess #为 true 时,将允许你在模块文件中以全局变量的形式访问 UMD 的导出
baseUrl #可以让您设置解析非绝对路径模块名时的基准目录
module #设置程序的模块系统
moduleResolution #指定模块解析策略:'node'(Node.js)或 'classic'
moduleSuffixes #提供一种在解析模块时覆盖要搜索的默认文件名后缀列表的方法
noResolve #默认情况下,TypeScript 将检查导入和 <reference 指令的初始文件集,并将这些解析的文件添加到您的程序中
paths #一些将模块导入重新映射到相对于 baseUrl 路径的配置
resolveJsonModule #允许导入带有“.json”扩展名的模块,这是 node 项目中的常见做法
rootDir #默认: 所有输入的非声明文件中的最长公共路径
rootDirs #通过 rootDirs,你可以告诉编译器有许多“虚拟”的目录作为一个根目录
typeRoots #默认情况下,所有 可见 的 ”@types” 包都将包含在你的编译过程中
types #默认情况下,所有 可见 的 ”@types” 包都将包含在你的编译过程中
+ +

Emit(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
declaration #
declarationDir #
declarationMap #
downlevelIteration #
emitBOM #
emitDeclarationOnly #
importHelpers #
importsNotUsedAsValues #
inlineSourceMap #
inlineSources #
mapRoot #
newLine #
noEmit #
noEmitHelpers #
noEmitOnError #
outDir #
outFile #
preserveConstEnums #
preserveValueImports #
removeComments #
sourceMap #
sourceRoot #
stripInternal #
+

JavaScript 支持(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + +
:---
allowJs #允许 JavaScript 文件在你的工程中被引入,而不是仅仅允许 .ts 和 .tsx 文件
checkJs #与 allowJs 配合使用,当 checkJs 被启用时,JavaScript 文件中会报告错误
maxNodeModuleJsDepth #在 node_modules 下搜索和加载 JavaScript 文件的最大依赖深度
+ +

编辑器支持(compilerOptions)

+ + + + + + + + + + + + + + + + + +
:---
disableSizeLimit #分配的内存量有一个上限。打开此标志将删除限制
plugins #可在编辑器内运行的语言服务插件列表
+ +

互操作约束(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
allowSyntheticDefaultImports #
esModuleInterop #
forceConsistentCasingInFileNames #
isolatedModules #
preserveSymlinks #
+

向后兼容性(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
charset #
keyofStringsOnly #
noImplicitUseStrict #
noStrictGenericChecks #
out #
suppressExcessPropertyErrors #
suppressImplicitAnyIndexErrors #
+

语言与环境(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
emitDecoratorMetadata #
experimentalDecorators #
jsx #
jsxFactory #
jsxFragmentFactory #
jsxImportSource #
lib #
moduleDetection #
noLib #
reactNamespace #
target #
useDefineForClassFields #
+

编译器诊断(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
diagnostics #
explainFiles #
extendedDiagnostics #
generateCpuProfile #
listEmittedFiles #
listFiles #
traceResolution #
+

项目(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
composite #
disableReferencedProjectLoad #
disableSolutionSearching #
disableSourceOfProjectReferenceRedirect #
incremental #
tsBuildInfoFile #
+

输出格式(compilerOptions)

+ + + + + + + + + + + + + + + + + + + + + +
:---
noErrorTruncation #
preserveWatchOutput #
pretty #
+

完整性(compilerOptions)

+ + + + + + + + + + + + + + + + + +
:---
skipDefaultLibCheck #
skipLibCheck #
+

监听选项(watchOptions)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:---
watchFile #
watchDirectory #
fallbackPolling #
synchronousWatchDirectory #
excludeDirectories #
excludeFiles #
+
+
{
+  "watchOptions": {
+    "synchronousWatchDirectory": true
+  }
+}
+
+

类型采集(typeAcquisition)

+ + + + + + + + + + + + + + + + + + + + + + + + + +
:---
enable #
include #
exclude #
disableFilenameBasedTypeAcquisition #
+
+
{
+  "typeAcquisition": {
+    "enable": false
+  }
+}
+