I am looking for some help with converting this JavaScript code to TypeScript. I am new to both languages, and when trying to access the 'this' object in my TypeScript version, I get an error message saying that 'this possibly be unknown'. Can someone please show me how to implement this code in TypeScript?
const singleton = {
instance: null, // socket.io instance
getInstance: (server) => {
if (!this.instance) {
this.instance = server; // takes 'Hello' as the value
}
return this.instance;
},
}
let a = singleton.getInstance('Hello');
let b = singleton.getInstance('World');
console.log(a === b); // true
console.log(a); // Hello
console.log(b); // Hello