refactor(frontend): `os.popup()`の`events`の型チェックを有効化 (#13165)

This commit is contained in:
zyoshoka 2024-02-05 15:02:30 +09:00 committed by GitHub
parent ddfc3b8a6a
commit 0df069494e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 3 deletions

View File

@ -128,9 +128,10 @@ export function promiseDialog<T extends Promise<any>>(
let popupIdCount = 0; let popupIdCount = 0;
export const popups = ref([]) as Ref<{ export const popups = ref([]) as Ref<{
id: any; id: number;
component: any; component: Component;
props: Record<string, any>; props: Record<string, any>;
events: Record<string, any>;
}[]>; }[]>;
const zIndexes = { const zIndexes = {
@ -144,7 +145,18 @@ export function claimZIndex(priority: keyof typeof zIndexes = 'low'): number {
return zIndexes[priority]; return zIndexes[priority];
} }
export async function popup<T extends Component>(component: T, props: ComponentProps<T>, events = {}, disposeEvent?: string) { // InstanceType<typeof Component>['$emit'] だとインターセクション型が返ってきて
// 使い物にならないので、代わりに ['$props'] から色々省くことで emit の型を生成する
// FIXME: 何故か *.ts ファイルからだと型がうまく取れない?ことがあるのをなんとかしたい
type ComponentEmit<T> = T extends new () => { $props: infer Props }
? EmitsExtractor<Props>
: never;
type EmitsExtractor<T> = {
[K in keyof T as K extends `onVnode${string}` ? never : K extends `on${infer E}` ? Uncapitalize<E> : K extends string ? never : K]: T[K];
};
export async function popup<T extends Component>(component: T, props: ComponentProps<T>, events: ComponentEmit<T> = {} as ComponentEmit<T>, disposeEvent?: keyof ComponentEmit<T>) {
markRaw(component); markRaw(component);
const id = ++popupIdCount; const id = ++popupIdCount;