Refering to Browser types in same named user/library classes

Topics: General, Language Specification
Dec 6, 2014 at 9:13 PM
Edited Dec 6, 2014 at 9:24 PM
Hi,

I am experimenting in rewriting backbone.js in TypeScript.

Refering to Browser/Platform types in same named user/library classes.

I have came across the following problem :-
export module Backbone {
    class History {
        public history: History;  // this should be the Browsers History Object 'class'
        public location: Location; // this IS the Browsers History object 'class'
        constructor() {
             this.history = window.history;
             this.location = window.location;  // error TS2012: Build: Cannot convert 'History' to 'History'
        }
    }
}
work around using a 'typeof' anchor :-
export module Backbone {
    class History {
        public history: typeof window.history;  // this IS an anchor to the Browsers History Object 'class'
        public location: Location; // this IS the Browsers History object 'class'
        constructor() {
             this.history = window.history;
             this.location = window.location;
        }
    }
}
Is there anyway of refereeing to (root) Browser classes within same named classes ?

In C++ you would say for example :-
class History {
    ::History *history;
    ...
};
I have looked in the TypeScript specification but cannot see anything to allow me to specify Platform classes over defined classes within modules or classes.

Many thanks in advance.
Dec 7, 2014 at 3:00 AM
This was brought up before.

https://typescript.codeplex.com/workitem/2287

You'll have to put up with work arounds for now. Side note - the project is moved to GitHub, so you might want to go there to see if the request has been moved there.