admin管理员组文章数量:1290927
I have Node-express code where modules are exported by using module.exports. For example, to export a function, it is written module.exports = functionName. Now the code will be converted to typescript. How to replace module.exports in typescript?
I have Node-express code where modules are exported by using module.exports. For example, to export a function, it is written module.exports = functionName. Now the code will be converted to typescript. How to replace module.exports in typescript?
Share Improve this question asked Jun 20, 2019 at 8:26 Sayan SahooSayan Sahoo 751 silver badge4 bronze badges 03 Answers
Reset to default 6Just use export
followed by the typical declaration, no matter whether it is a const
, function
, interface
, enum
, you name it.
export const myTestConst = () => console.log('hello world');
See https://www.typescriptlang/docs/handbook/modules.html
Adding up to duschsocke answer. You can also create a class with public methods and importing that class where you need those methods.
utils.ts
class Utils {
public static publicFunction() {
console.log('calling me');
}
}
On other ts file:
import * as utils from 'utils';
// Call the function
utils.publicFunction(); // Prints 'calling me' on console.
In TypeScript, use export = functionName
.
本文标签: nodejsConversion of moduleexports from javascript to typescriptStack Overflow
版权声明:本文标题:node.js - Conversion of module.exports from javascript to typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741512175a2382669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论