question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue.component doesnt except argument of type `Component`

See original GitHub issue

Version

2.5.17

Reproduction link

https://codesandbox.io/s/8z04jxj3y8

Steps to reproduce

  • Click repro link
  • Open test.ts
  • See type errors
  • Uncomment vue type augmentation to see errors disappear

What is expected?

I can pass any component to Vue.component

What is actually happening?

Type error:

Argument of type 'Component<DefaultData<never>, DefaultMethods<never>, DefaultComputed, Record<string, any>>' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Rec...'.
  Type 'VueConstructor<Vue>' is not assignable to type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Rec...'.
    Value of type 'VueConstructor<Vue>' has no properties in common with type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Rec...'. Did you mean to call it?

Adding the following overload to Vue.component will fix it:

    component<Data, Methods, Computed, Props>(
      id: string,
      definition: Component<Data, Methods, Computed, Props>,
    ): ExtendedVue<V, Data, Methods, Computed, Props>;

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
backbone87commented, Jul 14, 2019

any update on this?

i am using the following vue.d.ts in my projects, which solves the type problem according to @ktsn proposed solution:

import Vue, { Component } from 'vue';
import { ExtendedVue } from 'vue/types/vue';

declare module 'vue/types/vue' {
  interface VueConstructor<V extends Vue = Vue> {
    component<Data, Methods, Computed, Props>(
      id: string,
      definition: Component<Data, Methods, Computed, Props>,
    ): ExtendedVue<V, Data, Methods, Computed, Props>;
  }
}

0reactions
ktsncommented, Aug 29, 2018

I see your use case. I’m not sure that union type sometimes passes overload but we can replace fallback overload of component method with Component type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue js doesn't show props component properly - Stack Overflow
You're passing in an expression (23 - 05 - 2019). To get the correct output you either pass it in like so: datesel="23-05-2019"...
Read more >
vue-router doesn't accept components created with ... - GitHub
Steps to reproduce this repo: Create a new repo with vue-cli 3. My version was 3.12.1. Accept defaults (router, typescript).
Read more >
Components Basics - Vue.js
Components allow us to split the UI into independent and reusable pieces, and think about each piece in isolation. It's common for an...
Read more >
Generically Typed Vue.js Components - Abdelrahman Awad
The component will render correctly again, but the type information still doesn't work because typeof doesn't allow us to pass generics. The ...
Read more >
How to use Vue 3 with TypeScript - LogRocket Blog
The JavaScript-equivalent code would look like the following: ... To use props in our Vue component, we can use the props decorator.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found