You must understand that TypeScript is not a stand-alone programming language. It comes on-top of JavaScript, as a superset ( which means that once a TypeScript program is written and compiled, it is essentially a JavaScript program ). You could easily try writing the equivalent JavaScript code, if you want to do the trick. If you go to the TypeScript Playground you could really fast transpile your TS code into JS code ( if not too complex of course ) .
Anyway , here is a bit of a refresher how can you achieve what you asked :
var success = function () {
alert("JS method called");
typescriptMethod();
};
var MainClass = /** @class */ (function () {
function MainClass() {
success();
}
MainClass.prototype.typescriptmethod = function () {
alert("typescript method called");
};
return MainClass;
}());
This will give an error that typescripmethod() is not deifned , so you could make it static ( JS code) :
var MainClass = /** @class */ (function () {
function MainClass() {
success(); // JS method called
}
MainClass.typescriptMethod = function () {
alert("typescript method called");
};
return MainClass;
}());
var success = function () {
alert("JS method called"); // alert displayed
MainClass.typescriptMethod(); // Defined in class of typescript
};
success();
Or use a class instance ( JS code ) :
var MainClass = /** @class */ (function () {
function MainClass() {
success(this); // JS method called
}
MainClass.prototype.typescriptMethod = function () {
alert("typescript method called");
};
return MainClass;
}());
var success = function (instance) {
alert("JS method called"); // alert displayed
instance.typescriptMethod(); // Defined in class of typescript
};
success(new MainClass());
Hope this will do the trick for you .
new MainClass().typescriptmethod();