-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types: add AsyncComponentFactory type #8438
Conversation
👍 need this. quite annoying I can't use async component with @Component({
components: {
HelloComponent
}
}) this works.. @Component({
components: {
'dynamic-component': () => ({
component : import( 'from/some/index.vue' ),
loading : LoadingComponent
})
}
}) this currently throws a type error. Does this PR fix this? :D :D :D :D |
to make it work i had to do @Component<any>({ // <-- this
components: {
'dynamic-component': () => ({
component : import( 'from/some/index.vue' ),
loading : LoadingComponent
})
}
}) :/ |
@FeliciousX yes, this should fix this. |
types/options.d.ts
Outdated
@@ -86,7 +94,7 @@ export interface ComponentOptions< | |||
errorCaptured?(err: Error, vm: Vue, info: string): boolean | void; | |||
|
|||
directives?: { [key: string]: DirectiveFunction | DirectiveOptions }; | |||
components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> }; | |||
components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> | AsyncComponentFactory<any, any, any, any> }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overload isnt sufficient. At least createElement
needs overloads too.
I think it would be better to extend the AsyncComponent
type directly:
export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps>
= AsyncComponentPromise<Data, Methods, Computed, Props>
| AsyncComponentFactory<Data, Methods, Computed, Props>
export type AsyncComponentPromise<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = (
resolve: (component: Component<Data, Methods, Computed, Props>) => void,
reject: (reason?: any) => void
) => Promise<Component | EsModuleComponent> | void;
export type AsyncComponentFactory<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = () => {
component: AsyncComponentPromise<Data, Methods, Computed, Props>;
loading?: Component | EsModuleComponent;
error?: Component | EsModuleComponent;
delay?: number;
timeout?: number;
}
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
The current type definition for
ComponentOptions
does not have a definition for async component factories and as such causes errors when using the syntax with vue-class-component.