简体   繁体   English

如何使用参数导出Node.js中的Typescript类

[英]How to export Typescript class in Node.js with parameter

What I need is Typescript equivalent of 我需要的是Typescript等同于

require('mytypescriptfile')(optionsObject);

But TS code: 但是TS代码:

export class Animal {
 name: string;
 public bark(): string {
     return "bark " + this.name;
 }
 constructor(color:string) {    }
}

Produces this JS code: 产生此JS代码:

"use strict";
var Animal = (function () {
function Animal(color) {
}
Animal.prototype.bark = function () {
    return "bark " + this.name;
};
return Animal;
}());
exports.Animal = Animal;

No place for parameter in generated function. 参数在生成的函数中没有位置。 How do I do it? 我该怎么做?

const myTypescriptModule = require('myCOMPILEDtypescriptfile.js');

const whatIWant = new myTypescriptModule.Animal('red')

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

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