[英]TypeScript declarations for JavaScript module
I recently started using a Node library called bpmn-js
( npmjs.com) . 我最近开始使用名为
bpmn-js
( npmjs.com)的节点库。
It is written in JavaScript, and I'd like to have typings. 它是用JavaScript编写的,我想要打字。 Thus, I've began reading about
d.ts
files. 因此,我开始阅读有关
d.ts
文件的内容。
I created this folder structure 我创建了这个文件夹结构
webapp
@types
bpmn-js
index.d.ts
With a simple content 用简单的内容
declare module 'bpmn-js' {
export class BpmnJS {
constructor();
}
}
But this doesn't seem to work. 但这似乎不起作用。
"Before" typings, I was able to import the object I needed using “之前”打字,我能够导入我需要使用的对象
import BpmnJS from 'bpmn-js';
And I was able to instantiate it using 我能够使用它来实例化它
new BpmnJS();
How can I get the typings file to be recognized? 如何才能识别打字文件?
I'm using WebStorm 2019.1.*
. 我正在使用WebStorm
2019.1.*
。
Pretty simple, I was missing export default
, or better, the default
part. 非常简单,我缺少
export default
,或更好, default
部分。
declare module 'bpmn-js' {
export default class BpmnJS {
constructor(param?: { container: string });
...
}
}
Now this works too 现在这也有效
import BpmnJS from 'bpmn-js';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.