Home Ask Login Register

Developers Planet

Your answer is one click away!

Gabriel Kunkel February 2016

Uncaught TypeError: TypeScript class constructor is not a function

I have a class in one file and I'm trying to create new objects from it that are loaded up in my E2E $httpBackend, but the browser can't seem to figure it out. The whole application doesn't load and this error appears in the console:

Uncaught TypeError: app.Challenge is not a function

The TyepScript compiler (I'm using WebStorm to auto-compile.) has no complaints and it compiles fine. The module with the class is like so:

module app {
  "use strict";

    // interfaces here

    export class Challenge implements IChallenge {

        constructor(public answerString: string,
                    public difficulty: number,
                    public id: string,
                    public language: languages,
                    public name: string,
                    public tests: ITest[]) {

And my mockBackend for my angular app is this:

module app.development {
    "use strict";

        .module("appMock", ["ngMockE2E"])

    challengeResourceMock.$inject = ["$httpBackend"];
    function challengeResourceMock($httpBackend: ng.IHttpBackendService): void {
        var challenges: app.IChallenge[] = [];
        var challenge: app.IChallenge;

        challenge = new app.Challenge( // <-- It says this is not a function!
            "runThisFunction = function(str) {\n\treturn str.split('').reverse().join('');\n}",
            1, "1", 1, "Reverse a String", [{
                description: "make sure it reverses the string (e.g. 'start' will become 'trats)",
                test: "function () {\n\tvar a = 'abcdef';\n\texpect(runThisFunction(a)).toEqual('fedcba');\n}"

        // ...more challenges added to the list

        // get all challenges
        $httpBackend.whenGET("api/challenge").respond(200, challenges);

        // pass through requests for a        


basarat February 2016

Uncaught TypeError: app.Challenge is not a function

A common issue with using --out. Please use external modules (prefer --module commonjs).




Another answer: typescript output order - gulp equivalent to tsc with tsconfig.json

Post Status

Asked in February 2016
Viewed 3,530 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life