How do you write a node module using typescript?

后端 未结 2 939
遥遥无期
遥遥无期 2020-12-16 17:41

So, the general answer for the other question (How do you import a module using typescript) is:

1) Create a blah.d.ts definition file.

2) Use:

2条回答
  •  青春惊慌失措
    2020-12-16 18:08

    For JavaScript :

    var base = require('./base');
    var thing = require('./thing');
    module.exports = {
      Base: base.Base,
      Thing: thing.Thing
    };
    

    TypeScript :

    import base = require('./base');
    import thing = require('./thing');
    var toExport = {
      Base: base.Base,
      Thing: thing.Thing
    };
    export = toExport;
    

    Or even this typescript:

    import base = require('./base');
    import thing = require('./thing');
    export var Base = base.Base;
    export var Thing = thing.Thin;
    

提交回复
热议问题