Skip to content

Invalid type returned from createComponent for vue Router #130

@timshannon

Description

@timshannon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions