fix: type import (#2715)

(cherry picked from commit 7f2006488e)
This commit is contained in:
Himself65
2023-06-07 22:47:02 +08:00
committed by Alex Yang
parent cd5aec42a0
commit 28e05dc92c
24 changed files with 60 additions and 91 deletions
-6
View File
@@ -1,6 +0,0 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */
declare interface Window {
apis: import('./src/affine-apis').PreloadHandlers;
events: import('./src/affine-apis').MainIPCEventMap;
}
@@ -1,26 +1,6 @@
// NOTE: we will generate preload types from this file
import { ipcRenderer } from 'electron';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import type {
MainIPCEventMap,
MainIPCHandlerMap,
} from '../../main/src/exposed';
type WithoutFirstParameter<T> = T extends (_: any, ...args: infer P) => infer R
? (...args: P) => R
: T;
type HandlersMap<N extends keyof MainIPCHandlerMap> = {
[K in keyof MainIPCHandlerMap[N]]: WithoutFirstParameter<
MainIPCHandlerMap[N][K]
>;
};
export type PreloadHandlers = {
[N in keyof MainIPCHandlerMap]: HandlersMap<N>;
};
type MainExposedMeta = {
handlers: [namespace: string, handlerNames: string[]][];
events: [namespace: string, eventNames: string[]][];
@@ -35,7 +15,7 @@ const meta: MainExposedMeta = (() => {
})();
// main handlers that can be invoked from the renderer process
const apis: PreloadHandlers = (() => {
const apis: any = (() => {
const { handlers: handlersMeta } = meta;
const all = handlersMeta.map(([namespace, functionNames]) => {
@@ -55,7 +35,7 @@ const apis: PreloadHandlers = (() => {
})();
// main events that can be listened to from the renderer process
const events: MainIPCEventMap = (() => {
const events: any = (() => {
const { events: eventsMeta } = meta;
// NOTE: ui may try to listen to a lot of the same events, so we increase the limit...