I need to implement Singleton pattern in TypeScript. I have found a solution here but it seems like an overkill for me. After all, JavaScript is great in creating singletons.
Is it possible to write in TypeScript something like this (without getting an error)?
module Helpers {
Helpers.Singleton = {};
}
Currently, it correctly generates the output that I am expecting:
// Module
var Helpers;
(function (Helpers) {
Helpers.Singleton = {};
})(Helpers || (Helpers = {}));
But why is TypeScript piler inside my VisualStudio plaining about that (it says that it "Could not find symbol 'Helpers'." at line 2!)? Is it possible to write it in another way?
I need to implement Singleton pattern in TypeScript. I have found a solution here but it seems like an overkill for me. After all, JavaScript is great in creating singletons.
Is it possible to write in TypeScript something like this (without getting an error)?
module Helpers {
Helpers.Singleton = {};
}
Currently, it correctly generates the output that I am expecting:
// Module
var Helpers;
(function (Helpers) {
Helpers.Singleton = {};
})(Helpers || (Helpers = {}));
But why is TypeScript piler inside my VisualStudio plaining about that (it says that it "Could not find symbol 'Helpers'." at line 2!)? Is it possible to write it in another way?
Share Improve this question edited Nov 4, 2013 at 15:55 Roman Mazur asked Nov 4, 2013 at 15:47 Roman MazurRoman Mazur 5126 silver badges17 bronze badges1 Answer
Reset to default 10module Helpers {
export module Singleton {
export var etc = 4;
export function printSomething() {
// etc
}
}
}
// later...
Helpers.Singleton.printSomething();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744215840a4563549.html
评论列表(0条)