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

Merged
merged 2 commits into from Dec 5, 2018

Conversation

Projects
None yet
4 participants
@TimurKiyivinski
Contributor

TimurKiyivinski commented Jun 30, 2018

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe: Typescript

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

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.

@FeliciousX

This comment has been minimized.

FeliciousX commented Jul 10, 2018

👍 need this. quite annoying I can't use async component with vue-class-component .

@Component({
  components: {
    HelloComponent
  }
})

this works..
BUT

@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

@FeliciousX

This comment has been minimized.

FeliciousX commented Jul 10, 2018

to make it work i had to do

@Component<any>({ // <-- this
  components: {
    'dynamic-component': () => ({
      component : import( 'from/some/index.vue' ),
      loading : LoadingComponent    
    })
  }
})

:/

@TimurKiyivinski

This comment has been minimized.

Contributor

TimurKiyivinski commented Jul 10, 2018

@FeliciousX yes, this should fix this.

@@ -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> };

This comment has been minimized.

@backbone87

backbone87 Aug 30, 2018

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;
}

@KaelWD KaelWD referenced this pull request Oct 28, 2018

Closed

fix(types): add typings for async components state handling #8988

5 of 13 tasks complete

@yyx990803 yyx990803 added this to In progress in 2.6 Dec 5, 2018

@yyx990803 yyx990803 merged commit dfaf9e2 into vuejs:dev Dec 5, 2018

5 checks passed

ci/circleci: install Your tests passed on CircleCI!
Details
ci/circleci: lint-flow-types Your tests passed on CircleCI!
Details
ci/circleci: test-cover Your tests passed on CircleCI!
Details
ci/circleci: test-e2e Your tests passed on CircleCI!
Details
ci/circleci: test-ssr-weex Your tests passed on CircleCI!
Details

2.6 automation moved this from In progress to Done Dec 5, 2018

@yyx990803 yyx990803 removed this from Done in 2.6 Dec 5, 2018

@TimurKiyivinski TimurKiyivinski deleted the TimurKiyivinski:async-component-factory-type branch Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment