INTRO:
I'm relatively new to TypeScript (few weeks of practice), I'm slowly learning the superset and using it together with Electron. I was doing a extend of the BrowserWindow class to create extra functionality and porting part of my old pure JS code to TypeScript when a doubt arose, possibly because of some bad practice or for the TS does not accept my logic ...
DUVIDA:
I'm initializing other classes within the class in which I give BrowserWindow :
(the snippet is just to exemplify the code, since it will return error);
class Worker extends BrowserWindow {
public mouse: Mouse = new Mouse(this);
constructor(options: object) {
super(options);
}
};
It takes the this argument as the parent to have direct access to all Worker and BrowserWindow such as .getBounds () that returns the window area on the user's monitor.
However, passing the this to the Mouse class I have no idea of the correct way to declare it within the class, which type I should use, or the form correct to do this, the idea is not to extend the class anymore.
(Again, snippet just for code sample)
export class Mouse extends Steering {
// Qual tipo devo declarar a variavel???
public window: ???;
// Qual tipo devo passar o parametro ???
constructor (window: ???) {
super (new Vector(0, 0));
this.window = window;
}
}
Passing the any type to the window argument compiles without error, but I fail to have one of the highest qualities of TypeScript, since any wrong code I type it will pass without validation.
What would be the correct way to pass this to my Mouse class? What type do I use? Is my logic incorrect?
Thank you!