Answer the question
In order to leave comments, you need to log in
How to export from a closure in TypeScript?
I'm making a typescript plugin, I need to create a closure so as not to break someone else's code by accident. Without a closure, it exports normally:
class Model {
settings = {
min: 0,
max: 100
};
constructor(options: Object) {
this.settings = $.extend(this.settings, options);
}
static pow(num: number, pow: number): number {
return num ** pow;
}
}
export default Model;
(function($: any): void {
class Model {
settings = {
min: 0,
max: 100
};
constructor(options: Object) {
this.settings = $.extend(this.settings, options);
}
static pow(num: number, pow: number): number {
return num ** pow;
}
}
export default Model;
})(jQuery);
Answer the question
In order to leave comments, you need to log in
What you call a closure is the "module" pattern from the bearded old days, implemented through a closure. Your code is written in an ES2015 module, which eliminates the need for ancient "modules". Read how modules work. To solve your problem, you need a lot of leading questions and text - I'm too lazy)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question