File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,7 @@ const a:A = { x: 0, y: 0 };
252252某些第三方模块,原始作者没有提供接口类型,这时可以在自己的脚本顶部加上下面一行命令。
253253
254254``` typescript
255+ // 语法
255256declare module " 模块名" ;
256257
257258// 例子
@@ -371,6 +372,17 @@ declare module "path" {
371372
372373上面示例中,` url ` 和` path ` 都是单独的模块脚本,但是它们的类型都定义在` node.d.ts ` 这个文件里面。
373374
375+ 另一种情况是,使用` declare module ` 命令,为模块名指定加载路径。
376+
377+ ``` typescript
378+ declare module " lodash" {
379+ export * from " ../../dependencies/lodash" ;
380+ export default from " ../../dependencies/lodash" ;
381+ }
382+ ```
383+
384+ 上面示例中,` declare module "lodash" ` 为模块` lodash ` ,指定具体的加载路径。
385+
374386使用时,自己的脚本使用三斜杠命令,加载这个类型声明文件。
375387
376388``` typescript
Original file line number Diff line number Diff line change @@ -536,7 +536,9 @@ TypeScript 内置的类型描述文件,主要有以下一些,完整的清单
536536}
537537```
538538
539- 它还可以使用通配符“* ”。
539+ 上面示例中,paths 设置的是执行` require('b') ` 时,即加载的是` ./bar/b ` 。
540+
541+ 它还可以使用通配符“* ”,表明模块名与模块位置的对应关系。
540542
541543``` typescript
542544{
You can’t perform that action at this time.
0 commit comments