繁体   English   中英

如何使用es6语法在Typescript中导入功能模块

[英]How to use es6 syntax to import a function module in Typescript

我有一个简单的模块。 用于检查变量类型。

index.js

'use strict';
var typeOf = function (variable) {
    return ({}).toString.call(variable).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
};
module.exports = typeOf;

索引

export default typeOf;
declare function typeOf(value:any):string;

在这里我如何使用它。

import typeOf from 'lc-type-of';
typeOf(value);

但是代码无法按预期工作。 typeOf函数出现未定义的错误。 我想念什么吗?

当您使用Javascript导出节点时:

module.exports = something;

在Typescript中将其导入为:

import * as something from "./something"

在定义中

// Tell typescript about the signature of the function you want to export
declare const something: ()=> void ;

// tell typescript how to import it     
declare module something {
      // Module does Nothing , it simply tells about it's existence
}

// Export 
export =  something;

暂无
暂无

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

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