From 44bf2fdf10109fbb1d632adf2f55172598cdc0fd Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Fri, 25 Aug 2023 10:15:26 +0800 Subject: [PATCH] doc: update docs/typescript.md --- docs/typescript.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/typescript.md b/docs/typescript.md index 6b22c53..f3982e7 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -1528,7 +1528,6 @@ type Age2 = Person["age"]; ``` ### 范型推导出列表字面量 - ```ts const a = (t: T) => t; @@ -1538,8 +1537,24 @@ const d = a("a"); // const d: 'a' const e = a(1); // const d: 1 const f = a(true); // const d: true -const g = (t: [...T]) => t; // 这里t的类型用了一个展开运算 -const h = g(["111", "222"]); // 类型变成["111", "222"]了 +// 这里t的类型用了一个展开运算 +const g = + (t: [...T]) => t; +// 类型变成["111", "222"]了 +const h = g(["111", "222"]); +``` + +### Object.keys 类型声明 + + +```ts +const keys = Object.keys(options) as (keyof typeof options)[]; + +keys.forEach(key => { + if (options[key] == null) { + throw new Error(`Missing option ${key}`); + } +}); ``` .d.ts 模版 @@ -1994,6 +2009,7 @@ $ tsc app.ts util.ts --target esnext --outfile index.js ### 编译器选项 + :- | -- :- | -- @@ -2006,7 +2022,7 @@ $ tsc app.ts util.ts --target esnext --outfile index.js `--project` _string_ | 编译项目给定其配置文件的路径,或带有 'tsconfig.json' 的文件夹 `--showConfig` _boolean_ | 打印最终配置而不是构建 `--version` _boolean_ | 打印编译器的版本 - + ### 构建选项 @@ -2020,13 +2036,14 @@ $ tsc app.ts util.ts --target esnext --outfile index.js ### 监听选项 + :- | -- :- | -- `--excludeDirectories` _list_ | 从监视进程中删除目录列表 `--excludeFiles` _list_ | 从监视模式的处理中删除文件列表 `--fallbackPolling` _fixedinterval_, _priorityinterval_, _dynamicpriority_, _fixedchunksize_ | 指定当系统用完本机文件观察器时观察器应使用的方法 -`--synchronousWatchDirectory` boolean | 在本机不支持递归监视的平台上同步调用回调并更新目录监视程序的状态 +`--synchronousWatchDirectory` _boolean_ | 在本机不支持递归监视的平台上同步调用回调并更新目录监视程序的状态 `--watch` _boolean_ | 观看输入文件 `--watchDirectory` _usefsevents_, _fixedpollinginterval_, _dynamicprioritypolling_, _fixedchunksizepolling | 指定在缺少递归文件监视功能的系统上如何监视目录 `--watchFile` _fixedpollinginterval_, _prioritypollinginterval_, _dynamicprioritypolling_, _fixedchunksizepolling_, _usefsevents_, _usefseventsonparentdirectory_ | 指定 TypeScript 监视模式的工作方式