I have written a super small logger in a typescript class and placed it in a file call Log.ts. The file also contains a type definition. I would like to reference it as a library so that I can create an instance of that class in the script lab script. How do I do that?
I have placed the Log.ts file on a public website and referenced it in the Libraries tab in script lab but it is not getting picked up.
What do I need to do to be able to create a new logger as const log = new Log()?
Update
I have tried to create a minimal example. This is now the log.ts file:
export type PongType = "pong";
export class Log {
ping(): PongType {
return "pong";
}
}
I have compiled this to a log.js as:
var Log = /** @class */ (function () {
function Log() {
}
Log.prototype.ping = function () {
return "pong";
};
return Log;
}());
export { Log };
I have then placed log.js on a public server and then tried to import it in the HTML section in script lab as suggested in the comments. This is done as:
<script src="https://somedomain.com/log.js"></script>
But I still don't understand how I could create an instance of Log() in the Script lab script.
To my knowledge, there isn't a way to have Script Lab load TypeScript code directly from a .ts file using the Libraries tab. Script Lab can load public npm packages and JavaScript bundles. For example, the Office JS API is loaded as a JavaScript bundle from a .js file hosted on a CDN. I recommend you try compiling your logging code into a JavaScript bundle or publish a public npm package.