I have a simple TypeScript file as follows:
module HouseOfSynergy
{
export module Library
{
export class Version
{
private _Major: number = 0;
private _Minor: number = 0;
private _Build: number = 0;
private _Revision: number = 0;
public get Major(): number { return (this._Major); }
public get Minor(): number { return (this._Minor); }
public get Build(): number { return (this._Build); }
public get Revision(): number { return (this._Revision); }
constructor(major: number, minor: number, build: number, revision: number)
{
this._Major = major;
this._Minor = minor;
this._Build = build;
this._Revision = revision;
}
public toString(): string
{
return (this._Major.toString() + "." + this._Minor.toString() + "." + this._Build.toString() + "." + this._Revision.toString());
}
private static _Current: HouseOfSynergy.Library.Version = new HouseOfSynergy.Library.Version(1, 0, 0, 0);
public static get Current(): HouseOfSynergy.Library.Version { return (HouseOfSynergy.Library.Version._Current); }
}
}
}
The static property Current
is called from an HTML file as follows:
alert(HouseOfSynergy.Library.Version.Current.toString());
Google Chrome produces the following errors:
I have tried converting the static property to a function but keep getting the same error. Even declaring an instance of the Version
class new Version(1, 0, 0, 0)
produces the same error. Any pointers would be appreciated.
Here is the produced JavaScript:
var HouseOfSynergy;
(function (HouseOfSynergy) {
var Library;
(function (Library) {
var Version = (function () {
function Version(major, minor, build, revision) {
this._Major = 0;
this._Minor = 0;
this._Build = 0;
this._Revision = 0;
this._Major = major;
this._Minor = minor;
this._Build = build;
this._Revision = revision;
}
Object.defineProperty(Version.prototype, "Major", {
get: function () { return (this._Major); },
enumerable: true,
configurable: true
});
Object.defineProperty(Version.prototype, "Minor", {
get: function () { return (this._Minor); },
enumerable: true,
configurable: true
});
Object.defineProperty(Version.prototype, "Build", {
get: function () { return (this._Build); },
enumerable: true,
configurable: true
});
Object.defineProperty(Version.prototype, "Revision", {
get: function () { return (this._Revision); },
enumerable: true,
configurable: true
});
Version.prototype.toString = function () {
return (this._Major.toString() + "." + this._Minor.toString() + "." + this._Build.toString() + "." + this._Revision.toString());
};
Object.defineProperty(Version, "Current", {
get: function () { return (HouseOfSynergy.Library.Version._Current); },
enumerable: true,
configurable: true
});
Version._Current = new HouseOfSynergy.Library.Version(1, 0, 0, 0);
return Version;
}());
Library.Version = Version;
})(Library = HouseOfSynergy.Library || (HouseOfSynergy.Library = {}));
})(HouseOfSynergy || (HouseOfSynergy = {}));
When you are writing code within a namespace, you can omit the full namespace. Not only does this make code less verbose and more readable... it will also work...
module HouseOfSynergy
{
export module Library
{
export class Version
{
public static get Current(): Version { return (Version._Current); }
private static _Current: Version = new Version(1, 0, 0, 0);
public get Major(): number { return (this.major); }
public get Minor(): number { return (this.minor); }
public get Build(): number { return (this.build); }
public get Revision(): number { return (this.revision); }
constructor(private major: number, private minor: number, private build: number, private revision: number)
{
}
public toString(): string
{
return (this.major + "." + this.minor + "." + this.build + "." + this.revision);
}
}
}
}
alert(HouseOfSynergy.Library.Version.Current.toString());