忽略“找不到模块".打字稿上的错误 [英] Ignore "cannot find module" error on typescript
本文介绍了忽略“找不到模块".打字稿上的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Typescript编译器可以忽略导入表达式(例如:
Can the Typescript compiler ignore the cannot find module 'x'
error on import expressions such as:
//How to tell the compiler that this module does exists
import sql = require('sql');
有多个npm库,例如 node sql ,它们没有现有的类型
There are multiple npm libraries such as node sql that doesn't have existing typings
除了使用declare module x ...
创建新的定义文件以外,是否有办法告诉编译器忽略此错误?
Is there a way to tell the compiler to ignore this error other than creating a new definition file with the declare module x ...
?
推荐答案
如果只想绕过编译器,则可以为该模块创建.d.ts文件,例如,可以创建sql.d. ts文件和内部文件具有以下内容:
If you just want to bypass the compiler, you can create a .d.ts file for that module, for instance, you could create a sql.d.ts file and inside have this:
declare module "sql" {
let _sql: any;
export = _sql;
}
这篇关于忽略“找不到模块".打字稿上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文