wisetc / practice

Practice conclusion
5 stars 0 forks source link

typescript 第三方模块的模块定义 #23

Open wisetc opened 5 years ago

wisetc commented 5 years ago

第三方模块,例如md5,假设npm包中不包含类型定义文件(实际包含),需要自定义其为模块。

可以在项目的 src 文件下创建一个 @types 的文件夹,并将定义文件 md5/index.d.ts 放入其中。

目录结构如下图:

image

src/@types/md5/index.d.ts 的内容如:

declare module 'md5';

以上,完成了对第三方模块 md5 的 ts 定义。