Meteor + Typescript guideline

Hi all,

I tried to integrate both of these together for my demo project and look like I cannot find any official tutorial so far for this. This is what I come up with at this moment based on the Meteor todo list tutorial (https://github.com/bubuzzz/todo-meteor-typescript) with meteor-typescript-compiler

There is one thing struggling me at this moment. I want to leverage the inheritance feature of Typescript and thus, making a abstract class

export class AbstractService {
    constructor() {}
    
    public initMethod(method:{[key:string]:any}) {
        Meteor.methods(method);
    }
}

And in the child class

/// <reference path="../service/abstract.service.ts" />

import {AbstractService} from './abstract.service';

export class TaskService extends AbstractService {
    constructor() {
        super();
    }
    
    public addTask(params: any) {        
        Tasks.insert(params); 
    }
}

There is no issue during the compilation. The generated js file is like this

(function(){

/////////////////////////////////////////////////////////////////////////
//                                                                     //
// server/service/task.service.js                                      //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
                                                                       //
/// <reference path="../service/abstract.service.ts" />                // 1
var __extends = (this && this.__extends) || function (d, b) {          //
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];             //
    function __() { this.constructor = d; }                            //
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};                                                                     //
var abstract_service_1 = require('./abstract.service');                // 3
var TaskService = (function (_super) {                                 // 5
    __extends(TaskService, _super);                                    //
    function TaskService() {                                           //
        _super.call(this);                                             //
    }                                                                  //
    TaskService.prototype.addTask = function (params) {                //
        Tasks.insert(params);                                          //
    };                                                                 //
    return TaskService;                                                //
})(abstract_service_1.AbstractService);                                // 13
exports.TaskService = TaskService;                                     // 5
new TaskService();                                                     // 15
//# sourceMappingURL=task.service.js.map                               //
/////////////////////////////////////////////////////////////////////////

}).call(this);

//# sourceMappingURL=task.service.js.map

However, when I start server, meteor start to complain about

W20151201-13:15:56.765(7)? (STDERR) ReferenceError: exports is not defined
W20151201-13:15:56.765(7)? (STDERR)     at server/service/abstract.service:2:14
W20151201-13:15:56.765(7)? (STDERR)     at server/service/abstract.service:8:2

What should I do in order to make this work? If I add mrt:exports, it will continue to give error about ReferenceError: require is not defined

You code seems to use modules, which are currently not supported in Meteor.
Either you could look for the unofficial webpack projects that brings webpack to Meteor, or you will have to wait for 1.3, which (hopefully) will bring modules to meteor.

1 Like