Subscribe on changes!

Typing: mixin props definition not available in setup functions

avatar
Oct 10th 2020

Version

3.0.0

Reproduction link

https://codesandbox.io/s/confident-glade-9vqbb?file=/src/components/HelloWorld.vue

Steps to reproduce

  1. Have a mixin with some props definitions
  2. Use this mixin in a TypeScript component with a setup function
  3. The props defined in the mixin are available on this in options API methods and on props object of the setup function. However in the second case, props type doesn’t include the mixin props resulting in the following error:

    Property 'foo' does not exist on type 'Readonly<{} & { bar?: string; }>'.

What is expected?

Setup function props should be properly typed with both component own props and mixins props.

What is actually happening?

Props definitions from mixins are not available in setup functions.

avatar
Oct 11th 2020

Isn't this intentional? You aren't supposed to use mixins with setup.

avatar
Oct 11th 2020

@KaelWD That’s what I thought at first, but since the value is actually available it looks more like a bad typing to me. I don't think I’ve seen another way than mixins to share props definition between components.

avatar
Oct 20th 2020

@LeBenLeBen the types should reflect it, but you can share props definitions by simply spreading them.