[英]Typescript compilation for module imports
I am working with an npm module (node-rsa), trying to use typescript.我正在使用 npm 模块(node-rsa),尝试使用打字稿。 In the example for my module, I need to write some js like this (taken from the module docs).
在我的模块示例中,我需要编写一些这样的 js(取自模块文档)。
var NodeRSA = require('node-rsa');
var key = new NodeRSA({b: 512});
However, when I type this in TypeScript:但是,当我在 TypeScript 中输入时:
import {NodeRSA} from 'node-rsa';
var key = new NodeRSA({b: 512});
it compiles to:它编译为:
var node_rsa_1 = require('node-rsa');
var key = new node_rsa_1.NodeRSA({ b: 512 });
which throws the error:抛出错误:
"node_rsa_1.NodeRSA is not a function"
“node_rsa_1.NodeRSA 不是函数”
I am having to write my own .d.ts
file, as there is nothing on DT, so I am not sure if that makes any difference?我必须编写自己的
.d.ts
文件,因为 DT 上没有任何内容,所以我不确定这是否有什么区别?
I tried this on my project and it worked:我在我的项目中尝试了这个并且它有效:
import * as NodeRSA from 'node-rsa';
I think that's because node-rsa has a default export.我认为这是因为 node-rsa 具有默认导出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.