ClassExample.ts:
export class ClassExample{
constructor(){}
}
index.html:
<script src="ClassExample.js"></<script> // compiled to es5
<script>
var classExample = new ClassExample(); //ClassExample is not defined
</script>
Since I am using es5, I am unable to use import statements.
In regular javascript, you can achieve the following:
(function(global){
function ClassExample() {
}
global.ClassExample = ClassExample;
})(window);
How can I make a typescript class accessible on the window object?
The transpiled js file:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ClassExample = /** @class */ (function () {
function ClassExample() {
}
return ClassExample;
}());
exports.SomeClass = SomeClass;
});