-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
index.test-d.ts
91 lines (79 loc) · 2.42 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/// <reference lib="dom"/>
import {expectType, expectError} from 'tsd';
import {BrowserWindow} from 'electron';
import {ipcMain, ipcRenderer} from './index.js';
const browserWindow = BrowserWindow.getFocusedWindow()!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
// IpcMain
expectType<Promise<unknown>>(
ipcMain.callRenderer(browserWindow, 'get-emoji')
);
expectType<Promise<unknown>>(
ipcMain.callRenderer(browserWindow, 'get-emoji', 'unicorn')
);
expectType<Promise<unknown>>(
ipcMain.callRenderer<string>(browserWindow, 'get-emoji', 'unicorn')
);
expectType<Promise<string>>(
ipcMain.callRenderer<string, string>(browserWindow, 'get-emoji', 'unicorn')
);
expectType<Promise<string>>(
ipcMain.callRenderer(browserWindow, 'get-emoji', 'unicorn')
);
const detachListener = ipcMain.answerRenderer('get-emoji', emojiName => {
expectType<unknown>(emojiName);
return '🦄';
});
ipcMain.answerRenderer('get-emoji', async emojiName => {
expectType<unknown>(emojiName);
return '🦄';
});
ipcMain.answerRenderer<string>('get-emoji', async emojiName => {
expectType<string>(emojiName);
return '🦄';
});
ipcMain.answerRenderer<string, string>('get-emoji', async emojiName => {
expectType<string>(emojiName);
return '🦄';
});
ipcMain.answerRenderer<string, string>(browserWindow, 'get-emoji', async emojiName => {
expectType<string>(emojiName);
return '🦄';
});
expectType<() => void>(detachListener);
detachListener();
ipcMain.sendToRenderers('get-emoji');
ipcMain.sendToRenderers('get-emoji', '🦄');
ipcMain.sendToRenderers<string>('get-emoji', '🦄');
expectError(ipcMain.callMain);
// IpcRenderer
expectType<Promise<unknown>>(
ipcRenderer.callMain('get-emoji', 'unicorn')
);
expectType<Promise<unknown>>(
ipcRenderer.callMain<string>('get-emoji', 'unicorn')
);
expectType<Promise<string>>(
ipcRenderer.callMain<string, string>('get-emoji', 'unicorn')
);
const detachListener2 = ipcRenderer.answerMain(
'get-emoji',
async emojiName => {
expectType<unknown>(emojiName);
return '🦄';
}
);
ipcRenderer.answerMain('get-emoji', emojiName => {
expectType<unknown>(emojiName);
return '🦄';
});
ipcRenderer.answerMain<string>('get-emoji', emojiName => {
expectType<string>(emojiName);
return '🦄';
});
ipcRenderer.answerMain<string, string>('get-emoji', emojiName => {
expectType<string>(emojiName);
return '🦄';
});
expectType<() => void>(detachListener2);
detachListener();
expectError(ipcRenderer.callRenderer);