angularjs - Uncaught TypeError: TypeScript class constructor is not a function -
i have class in 1 file , i'm trying create new objects loaded in e2e $httpbackend, browser can't seem figure out. whole application doesn't load , error appears in console:
uncaught typeerror: app.challenge not function
the tyepscript compiler (i'm using webstorm auto-compile.) has no complaints , compiles fine. module class 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 mockbackend angular app this:
module app.development { "use strict"; angular .module("appmock", ["ngmocke2e"]) .run(challengeresourcemock); challengeresourcemock.$inject = ["$httpbackend"]; function challengeresourcemock($httpbackend: ng.ihttpbackendservice): void { var challenges: app.ichallenge[] = []; var challenge: app.ichallenge; challenge = new app.challenge( // <-- says not function! "runthisfunction = function(str) {\n\treturn str.split('').reverse().join('');\n}", 1, "1", 1, "reverse string", [{ description: "make sure reverses string (e.g. 'start' become 'trats)", test: "function () {\n\tvar = 'abcdef';\n\texpect(runthisfunction(a)).toequal('fedcba');\n}" }]); challenges.push(challenge); // ...more challenges added list // challenges $httpbackend.whenget("api/challenge").respond(200, challenges); // pass through requests else $httpbackend.whenget(/./).passthrough(); } } how clear error , app working mock backend?
update:
i've removed typescript modules. on basarat's advice i'm using commonjs modules. i'm using ts-loader webpack instead of webstorm's compiler. added tsconfig file:
{ "compileroptions": { "target": "es5", "module": "commonjs", "noimplicitany": true, "outdir": "./dist/tsoutput/", "preserveconstenums": true, "removecomments": true, "sourcemap": true }, "exclude": ["node_modules", "trash", "coverage"] } currently in global space, isn't ideal application isn't big enough yet there conflicts. i'm, now, getting different error message, effect same. application won't run.
uncaught referenceerror: challenge not defined
"build" doesn't seem working. ide's inspector has no complaints. it's if "class" isn't doing @ all.
temporary hack
well, after fiddling quite while, decided running out of time , decided replace challenge objects object literals.
module app { "use strict"; angular .module("appmock", ["ngmocke2e"]) .run(challengeresourcemock); challengeresourcemock.$inject = ["$httpbackend"]; function challengeresourcemock($httpbackend: ng.ihttpbackendservice): void { var challenges: app.ichallenge[] = []; var challenge: app.ichallenge; challenge = { answerstring: "runthisfunction = function(str) {\n\treturn str.split('').reverse().join('');\n}", difficulty: 1, id: "1", language: 1, name: "reverse string", tests: [{ description: "make sure reverses string (e.g. 'start' become 'trats)", test: "function () {\n\tvar = 'abcdef';\n\texpect(runthisfunction(a)).toequal('fedcba');\n}" }] }; challenges.push(challenge); // additional obj literal challenges // challenges $httpbackend.whenget("api/challenge").respond(200, challenges); // pass through requests else $httpbackend.whenget(/./).passthrough(); } } obviously, must return issue in future, i'm further in project now.
uncaught typeerror: app.challenge not function
a common issue using --out. please use external modules (prefer --module commonjs).
docs
https://github.com/typestrong/atom-typescript/blob/master/docs/out.md
more
another answer: typescript output order - gulp equivalent tsc tsconfig.json
Comments
Post a Comment