Vue.component doesnt except argument of type `Component`
See original GitHub issueVersion
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:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:I see your use case. I’m not sure that union type sometimes passes overload but we can replace fallback overload of
component
method withComponent
type.