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

Invalid type returned from createComponent for vue Router #130

Closed
timshannon opened this issue Sep 12, 2019 · 0 comments
Closed

Invalid type returned from createComponent for vue Router #130

timshannon opened this issue Sep 12, 2019 · 0 comments

Comments

@timshannon
Copy link

When I import a component created via createComponent into a route in a vue Router, I get the following error.

import Page from "/view/Page.vue";

 const router = new Router({
     mode: "history",
     routes: [
         {
             path: "/",
             name: "root",
             component: Page,
         },
 ]});
 Argument of type '{ mode: "history"; base: string | undefined; routes: ({ path: string; name: string; component: typeof Buttons; } | { path: string; name: string; component: typeof NotFound; meta: { public: boolean; }; } | { path: string; name: string; component: typeof Unauthorized; props: true; meta: { ...; }; } | { ...; })[]; }' is not assignable to parameter of type 'RouterOptions'.
  Types of property 'routes' are incompatible.
    Type '({ path: string; name: string; component: typeof Buttons; } | { path: string; name: string; component: typeof NotFound; meta: { public: boolean; }; } | { path: string; name: string; component: typeof Unauthorized; props: true; meta: { ...; }; } | { ...; })[]' is not assignable to type 'RouteConfig[]'.
      Type '{ path: string; name: string; component: typeof Buttons; } | { path: string; name: string; component: typeof NotFound; meta: { public: boolean; }; } | { path: string; name: string; component: typeof Unauthorized; props: true; meta: { ...; }; } | { ...; }' is not assignable to type 'RouteConfig'.
        Type '{ path: string; name: string; component: VueProxy<{ url: StringConstructor; }, void>; props: true; meta: { public: boolean; }; }' is not assignable to type 'RouteConfig'.
          Types of property 'component' are incompatible.
            Type 'VueProxy<{ url: StringConstructor; }, void>' is not assignable to type 'VueConstructor<Vue> | ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>> | AsyncComponentPromise<...> | AsyncComponentFactory<...> | undefined'.
              Type 'ComponentOptions<never, void, never, never, { url: StringConstructor; }, ExtractPropTypes<{ url: StringConstructor; }, false>> & VueConstructorProxy<{ url: StringConstructor; }, void>' is missing the following properties from type 'VueConstructor<Vue>': extend, nextTick, set, delete, and 9 more.

I can get rid of the error by manually setting the type to VueConstructor:

import Page from "/view/Page.vue";

 const router = new Router({
     mode: "history",
     routes: [
         {
             path: "/",
             name: "root",
             component: Page as Vue.VueConstructor,
         },
 ]});

It appears createComponent isn't returning a compatible type? I'm on typescript 3.6.2 and Vue Router 3.1.3.

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

No branches or pull requests

1 participant