Hi @Jalibu,
thanks for the typings.
To be honest, it’s not the best possible integration. The MagicMirror repository includes a module-types.ts file, containing the most important types, which I extended a little to fit my needs. A deeper integration, like being able to get correct typings/autocompletion for the this object in functions, is not available. If I find myself using it more in the future, I may look into improving this.
I want to share an little extension or may a solution for the problem quoted:
import type { Config } from "../types/Config";
import type { State } from "../types/State";
interface FrontendModuleProperties
extends Partial<Module.ModuleProperties<Config>> {
state?: State;
}
Module.register<Config>("MMM-XX", {
defaults: {
x: 29,
y: "abc",
},
getStyles() {
return ["z.css"];
},
<...>
getTemplateData() {
return {
config: this.config,
value: this.state?.value,
};
},
<...>
socketNotificationReceived(notificationIdentifier: string, payload: State) {
if (notificationIdentifier === `ABC-${this.identifier}`) {
const lastValue = this.state?.value; // <-- Here lastValue got correct type automatically
<...>
this.state = payload;
}
},
} as FrontendModuleProperties);