The problem I'm facing is that I am unable - outside of a class definition - to create functions with names that are the same as keywords.
This same "issue" occurs with other keywords, but delete
is the keyword of interest here.
THIS WORKS:
class WebServiceInterface {
create(): void { }
retrieve(): void { }
update(): void { }
delete(): void { }
}
Notice that I have a function member named "delete".
BUT THIS DOES NOT WORK:
class WebServiceInterface {
create(): void { }
retrieve(): void { }
update(): void { }
delete(): void { }
}
module Web {
var defaultInterface = new WebServiceInterface();
export function create() { defaultInterface.create(); }
export function retrieve() { defaultInterface.retrieve(); }
export function update() { defaultInterface.update(); }
export function delete() { defaultInterface.delete(); }
}
The delete
portion of export function delete
causes these errors:
Is there a fundamental reason why this couldn't/shouldn't be allowed? Is this perhaps just something that needs to be implemented in the language? Is there another way to achieve this?
For reference, I'm using TypeScript 1.4 inside of Visual Studio 2013.
The problem here is that delete is a reserved word in JavaScript.
The code generated with the delete block removed is:
var WebServiceInterface = (function () {
function WebServiceInterface() {
}
WebServiceInterface.prototype.create = function () {
};
WebServiceInterface.prototype.retrieve = function () {
};
WebServiceInterface.prototype.update = function () {
};
WebServiceInterface.prototype.delete = function () {
};
return WebServiceInterface;
})();
var Web;
(function (Web) {
var defaultInterface = new WebServiceInterface();
function create() {
defaultInterface.create();
}
Web.create = create;
function retrieve() {
defaultInterface.retrieve();
}
Web.retrieve = retrieve;
function update() {
defaultInterface.update();
}
Web.update = update;
})(Web || (Web = {}));
Guess what code it would try to generate when uncommenting the delete block?
function delete() {
defaultInterface.delete();
}
Web.delete = delete;
The problem is that is not valid JavaScript since delete is a reserved word.