Skip to content

Commit a633aaf

Browse files
authored
🤖 Merge PR DefinitelyTyped#72985 feat(magicmirror-module): update the return type of NodeHelper.create and start() in Module.register by @hermanho
1 parent 0a5efd9 commit a633aaf

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

‎types/magicmirror-module/index.d.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare namespace Module {
1818
// Subclassable methods
1919
init: () => void;
2020
loaded: (callback?: () => void) => void;
21-
start: () => void;
21+
start: () => void | Promise<void>;
2222
getScripts: () => string[];
2323
getStyles: () => string[];
2424
getTranslations: () => { [key: string]: string };
@@ -50,7 +50,9 @@ declare namespace Module {
5050

5151
/* tslint:disable:no-single-declare-module */
5252
declare module "node_helper" {
53-
function create(object: ThisType<NonNullable<NodeHelperModule>> & Partial<NodeHelperModule>): void;
53+
function create<T>(
54+
object: ThisType<T & NonNullable<NodeHelperModule>> & Partial<NodeHelperModule>,
55+
): new() => T & NodeHelperModule;
5456

5557
interface NodeHelperModule {
5658
readonly name: string;

‎types/magicmirror-module/magicmirror-module-tests.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ Module.register<TestConfig>("test", {
9191
hidden: false,
9292
});
9393

94-
NodeHelper.create({
94+
Module.register<TestConfig>("test2", {
95+
async start() {
96+
console.log("started");
97+
await Promise.resolve();
98+
},
99+
});
100+
101+
const ModuleClass = NodeHelper.create({
95102
start() {
96103
Log.debug("Starting module: " + this.name);
97104
return;
@@ -113,3 +120,8 @@ NodeHelper.create({
113120
console.log("hi");
114121
},
115122
});
123+
124+
const moduleInstance = new ModuleClass();
125+
moduleInstance.start();
126+
moduleInstance.start();
127+
moduleInstance.socketNotificationReceived("abc", { data: "test" });

0 commit comments

Comments
 (0)