[英]Why can't I import sprintf-js in TypeScript
I have a TypeScript file into which I'm importing third-party libraries.我有一个 TypeScript 文件,我要在其中导入第三方库。
import * as _ from 'lodash'; // Works great!
import * as moment from 'moment'; // Works great!
import {vsprintf} from 'sprintf-js'; // Compiler error
As my comments explain, the first two imports work great, but the sprintf-js import does not.正如我的评论所解释的,前两个导入效果很好,但 sprintf-js 导入效果不佳。 I get the following compiler error:
我收到以下编译器错误:
Error TS2307: Cannot find module 'sprintf-js'.
错误 TS2307:找不到模块“sprintf-js”。
Without a doubt, I have sprintf-js
inside of my node_modules
folder.毫无疑问,我的
node_modules
文件夹中有sprintf-js
。 I'm not very knowledgeable about node modules.我对节点模块不是很了解。 I'm guessing that the sprintf-js libarary does something different than lodash or moment and that TypeScript doesn't like it.
我猜sprintf-js 库做了一些与 lodash 或 moment 不同的事情,TypeScript 不喜欢它。 How can I make this work?
我怎样才能使这项工作?
You will need to add a typing definition for sprintf-js
.您需要为
sprintf-js
添加类型定义。 Depending on your setup - if you have TSD installed and setup with your project, it would be a case of running:根据您的设置 - 如果您安装了 TSD 并设置了您的项目,则将是运行的情况:
tsd query sprintf-js --action save
otherwise, you can have a read here:否则,你可以在这里阅读:
http://definitelytyped.org/ http://definelytyped.org/
or simply download the typing definition and include it in the project root folder:或者简单地下载类型定义并将其包含在项目根文件夹中:
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/sprintf-js/sprintf-js.d.ts https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/sprintf-js/sprintf-js.d.ts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.