I'm very new to Typescript, just exploring how to convert our existing JS code. My approach (which may well be flawed) is to do the minimal to just get it working in TypeScript, and then gradually convert it to follow "best practices".
I seem to have fallen at the first hurdle.....
I have the following TypeScript, using jQuery (in an ASP.NET .NET5 application).
interface MyInterface {
prop1: string;
prop2: number;
}
const something = {
currentThing : MyInterface,
init: (): void => {
//
}
};
$(something.init);
So the idea is that when the page loads, something.init will be executed. This will set up things like event handlers via jQuery selectors, etc. etc. All that part seems to work just fine.
However...
At some point, an event handler will fire and I'll create a new object that will implement MyInterface. I'll need to preserve that (by setting it to be the value of the property/field currentThing) so that it can then be accessed by future events.
However, Typescript doesn't like the line currentActivity: MyInterface, and I get the error:
'MyInterface' only refers to a type, but is being used as a value here.