async-component-test.ts 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Vue, { AsyncComponent, Component } from '../index'
  2. const a: AsyncComponent = () => ({
  3. component: new Promise<Component>((res, rej) => {
  4. res({ template: '' })
  5. })
  6. })
  7. const b: AsyncComponent = () => ({
  8. // @ts-expect-error component has to be a Promise that resolves to a component
  9. component: () =>
  10. new Promise<Component>((res, rej) => {
  11. res({ template: '' })
  12. })
  13. })
  14. const c: AsyncComponent = () =>
  15. new Promise<Component>((res, rej) => {
  16. res({
  17. template: ''
  18. })
  19. })
  20. const d: AsyncComponent = () =>
  21. new Promise<{ default: Component }>((res, rej) => {
  22. res({
  23. default: {
  24. template: ''
  25. }
  26. })
  27. })
  28. const e: AsyncComponent = () => ({
  29. component: new Promise<{ default: Component }>((res, rej) => {
  30. res({
  31. default: {
  32. template: ''
  33. }
  34. })
  35. })
  36. })
  37. // Test that Vue.component accepts any AsyncComponent
  38. Vue.component('async-compponent1', a)