File tree 2 files changed +15
-1
lines changed
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 };
252
252
某些第三方模块,原始作者没有提供接口类型,这时可以在自己的脚本顶部加上下面一行命令。
253
253
254
254
``` typescript
255
+ // 语法
255
256
declare module " 模块名" ;
256
257
257
258
// 例子
@@ -371,6 +372,17 @@ declare module "path" {
371
372
372
373
上面示例中,` url ` 和` path ` 都是单独的模块脚本,但是它们的类型都定义在` node.d.ts ` 这个文件里面。
373
374
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
+
374
386
使用时,自己的脚本使用三斜杠命令,加载这个类型声明文件。
375
387
376
388
``` typescript
Original file line number Diff line number Diff line change @@ -536,7 +536,9 @@ TypeScript 内置的类型描述文件,主要有以下一些,完整的清单
536
536
}
537
537
```
538
538
539
- 它还可以使用通配符“* ”。
539
+ 上面示例中,paths 设置的是执行` require('b') ` 时,即加载的是` ./bar/b ` 。
540
+
541
+ 它还可以使用通配符“* ”,表明模块名与模块位置的对应关系。
540
542
541
543
``` typescript
542
544
{
You can’t perform that action at this time.
0 commit comments