简体   繁体   English

如何在Typescript中声明NodeJs模块?

[英]How do I declare a NodeJs module in Typescript?

My consuming Node code looks like this: 我的消费节点代码如下所示:

var helloworld = require('helloworld');
helloworld.sayhello();

Using the Typescript goodness, how would I declare the module exporting the sayhello() function? 使用Typescript的优点,我如何声明导出sayhello()函数的模块?

helloworld.ts helloworld.ts

export function sayhello() {
    console.log('hello, world!');
}

Note that you would not write a containing module block (the file itself is the module). 请注意,您不会编写包含module块(文件本身就是模块)。

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

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