Skip to content
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

Incorrect type for AsyncComponentFactory #11990

Closed
Esurnir opened this issue Mar 31, 2021 · 3 comments · Fixed by #11906
Closed

Incorrect type for AsyncComponentFactory #11990

Esurnir opened this issue Mar 31, 2021 · 3 comments · Fixed by #11906

Comments

@Esurnir
Copy link

Esurnir commented Mar 31, 2021

Version

2.6.11

Reproduction link

https://github.com/Esurnir/repro-types-vue

Steps to reproduce

clone the repo and do yarn followed by a yarn serve, open the browser.

The test case is in App.vue

What is expected?

MyComponent1 which is a correctly typed AsyncComponent should render. It contains a component property which is of type AsyncComponentPromise which is a fonction that returns a promise.

MyComponent2 which is incorrectly typed as component is of type Promise<EsModuleComponent> should not load properly.

What is actually happening?

The opposite.


This is due to this line
which checks wether component is a promise, not a function which returns a promise.

Among the two ways this could be fixed :
component could be of type Promise<Component | EsModuleComponent> instead of the maybe confusingly named AsyncComponentPromise. Or resolveAsyncComponent could have a third case where if res.component is of type Function, it should call res.component(resolve, reject) and test if -that- is a promise before failing.

@posva
Copy link
Member

posva commented Mar 31, 2021

FYI you should use defineAsyncComponent(): https://v3.vuejs.org/api/global-api.html#defineasynccomponent nvm I thought you were using Vue 3

@posva posva linked a pull request Mar 31, 2021 that will close this issue
13 tasks
@posva
Copy link
Member

posva commented Mar 31, 2021

there is already an opened PR to fix this

@Esurnir
Copy link
Author

Esurnir commented Mar 31, 2021

Ah sorry my bad. My googlefoo failed me this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants