TS检测的报错截图如下:

【问题记录】Cannot find module or its corresponding type declarations._npm

 

问题描述:

当我们用 TS 去写项目代码时,并且引入了一个没有类型声明的 npm 包的时候,此时 TS 会检测提示导入了一个不明物体!于是,强迫症表示太难受了。。。咋办呢?

1、最简单粗暴的解决方法:

注释TS检测 @ts-ignore

【问题记录】Cannot find module or its corresponding type declarations._typescript_02

2、理想解决方案:

在根目录(src)下面帮忙声明一下该类型,新建一个 XXX.d.ts

【问题记录】Cannot find module or its corresponding type declarations._npm_03

 

参考资料:

【问题记录】Cannot find module or its corresponding type declarations._npm_04

摘自:typescript error ts2307 cannot find module or its corresponding type declarations

【问题记录】Cannot find module or its corresponding type declarations._解决方法_05

 

【问题记录】Cannot find module or its corresponding type declarations._参考资料_06

摘自:How to Fix cannot find module and its corresponding type declarations