In TypeScript I have this simple code:
namespace Customer {
function onOpen() {
}
}
It generates:
var Customer;
(function (Customer) {
function onOpen() {
}
})(Customer || (Customer = {}));
In order for Kendo to use onOpen
the JS needs to look like this (Notice the onOpen
). Is this possible?:
var Customer;
(function (Customer) {
Customer.onOpen = function () {
}
})(Customer || (Customer = {}));
In TypeScript I have this simple code:
namespace Customer {
function onOpen() {
}
}
It generates:
var Customer;
(function (Customer) {
function onOpen() {
}
})(Customer || (Customer = {}));
In order for Kendo to use onOpen
the JS needs to look like this (Notice the onOpen
). Is this possible?:
var Customer;
(function (Customer) {
Customer.onOpen = function () {
}
})(Customer || (Customer = {}));
Share
Improve this question
asked Nov 2, 2017 at 16:19
Ian VinkIan Vink
68.9k107 gold badges353 silver badges567 bronze badges
2
- Are you getting an error at runtime with KendoUI? If so, can you add that? It would surprise me if that is the case, as there isn't much difference in those declarations. You could perhaps set a property that is a function instead of a method, I can write an answer for that. But adding the console error would be helpful. – Sean Newell Commented Nov 2, 2017 at 16:21
- Actually disregard my ment, @MinusFour got it right - your function is just not exposed / exported. – Sean Newell Commented Nov 2, 2017 at 16:27
2 Answers
Reset to default 5Add export
:
namespace Customer {
export function onOpen() {
}
}
Produces:
var Customer;
(function (Customer) {
function onOpen() {
}
Customer.onOpen = onOpen;
})(Customer || (Customer = {}));
You need to export exposed properties, and since functions are first class citizens, you can write typescript code like this :
namespace Customer {
export const onOpen = () => {}
}
Or instead of a lambda just with normal function
namespace Customer {
export const onOpen = function() {}
}
Or this will work
namespace Customer {
export function onOpen() { }
}
That will generate a property that points to a function instead of a function member - essentially the same thing really.
Javascript output:
var Customer;
(function (Customer) {
Customer.onOpen = function () { };
})(Customer || (Customer = {}));