Is TypeScript sensitive to the order of type declarations?
Changing the order of type causes an error inside Angular 2 (beta.0) which (AFAIK) is implemented using TypeScript itself (that's why this error seems so strange & irrelevant to me):
angular2-polyfills.js:138 Error: Cannot read property 'prototype' of undefined(…)
Assume we have a file t1.ts
:
export class AuthResponse extends JsonResponse { }
export class JsonResponse {
public code: ResultCode;
}
export enum ResultCode { }
When starting the app, we see the mentioned error, at client side. But if we reverse the order of declarations in this file, the error goes away (Just for the record, currently I'm moving forward, keeping this in mind & it works).
To reproduce this error we need five more files:
t2.ts
:
import {AuthResponse, JsonResponse, ResultCode} from './t1'; // this order?
export class DummyAction {
doSomething() {
console.log('test, starting ...');
var v = new AuthResponse();
return v;
}
}
app.component.ts
:
import {Component, OnInit} from 'angular2/core';
import {DummyAction} from './components/t2';
@Component({
selector: 'root-app',
templateUrl: '/app/templates/app.html',
})
export class AppComponent implements OnInit {
constructor() {
var tester = new DummyAction();
// tester.runTest();
}
ngOnInit() { }
}
app.html
:
<h1>TEST</h1>
boot.ts
:
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent, []);
And index.html
which is a bit larger but essentially, has the structure of index.html
from tutorial on angular website.