简体   繁体   English

导入导出默认打字稿

[英]import a export default typescript

I try to use the numbro js library using typescript. 我尝试通过打字稿使用numbro js库。 Their numbro.d.ts export stuffs like that 他们的numbro.d.ts会输出类似的内容

declare const numbro: NumbroStatic;
export default numbro;

So I tried a very simple import 所以我尝试了一个非常简单的导入

import numbro from 'numbro'; 
var string = numbro(1000).format('0,0');
console.log(string);

From the typescript part, that seem ok, I can tsc my file without error. 从打字稿部分看,似乎还可以,我可以无错误地对文件进行tsc。 JS generated code is JS生成的代码是

"use strict";
var numbro_1 = require('numbro');
var string = numbro_1["default"](1000).format('0,0');
console.log(string);

Now, if I try to execute this code, I have this error : 现在,如果我尝试执行此代码,则会出现此错误:

numbro_1.default is not a function

If I change the js manually to 如果我手动将js更改为

numbro_1(1000).format('0,0');

it works. 有用。 Did I missed something? 我错过了什么吗? It is a problem in their js export or that come from my code? 这是他们的js导出问题还是来自我的代码?

Thanks 谢谢

采用:

import * as numbro from 'numbro';

Use 采用

import numbro = require("numbro");

See also this answer: What does "... resolves to a non-module entity and cannot be imported using this construct" mean? 另请参见以下答案: “ ...解析为非模块实体并且无法使用此构造导入”是什么意思? for why you should do this 为什么要这样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM