perf: 为createAsyncComponent函数增加类型推导 (#2967) (#2991)

This commit is contained in:
invalid w 2023-09-03 16:21:51 +08:00 committed by GitHub
parent 1c1ce4b0e3
commit a9017da294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -1,4 +1,7 @@
import {
AsyncComponentLoader,
Component,
ComponentPublicInstance,
defineAsyncComponent,
// FunctionalComponent, CSSProperties
} from 'vue';
@ -27,7 +30,11 @@ interface Options {
retry?: boolean;
}
export function createAsyncComponent(loader: Fn, options: Options = {}) {
export function createAsyncComponent<
T extends Component = {
new (): ComponentPublicInstance;
},
>(loader: AsyncComponentLoader<T>, options: Options = {}) {
const { size = 'small', delay = 100, timeout = 30000, loading = false, retry = true } = options;
return defineAsyncComponent({
loader,