简体   繁体   English

从TypeScript中的模块调用导出的函数

[英]Invoking an exported function from module in TypeScript

The question is a simple one. 这个问题很简单。

Here is how the module exports the function. 这是模块导出功能的方式。

exports = module.exports = debug.debug = debug;

Here is how the ES5 module consumes it. 这是ES5模块使用它的方式。

var debug = require('debug')('http')

Now in Typescript it's a bit different. 现在在Typescript中有所不同。

import * as debug from 'debug';

This returns a strange object that I have never seen before, a nested object without a key value pair. 这将返回一个我从未见过的奇怪对象,一个没有键值对的嵌套对象。

{ [Function: debug]
  coerce: [Function: coerce],
  disable: [Function: disable],
  // More properties go here
}

How do I invoke the function debug 如何调用功能debug

I found it digging through the documentation 我发现它深入文档中

const log = debug('http');
log.log = console.log.bind(console); // binding to console

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

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