Skip to content

Typescript error when mounting component with boolean prop #237

Closed
@nekosaur

Description

@nekosaur

The following code shows a typescript error on the first mount call. It only seems to appear when adding a boolean prop.

import { mount } from '@vue/test-utils'
import { defineComponent, h } from 'vue'

const Foo = defineComponent({
  name: 'Foo',
  props: {
    bar: Boolean,
    baz: String,
  },
  setup () {
    return () => h('div', ['hello world'])
  }
})

test('uses mounts', async () => {
  mount(Foo, {
    props: {
      baz: 'hello',
    }
  })

  mount(Foo, {
    props: {
      bar: true,
    }
  })
})
No overload matches this call.
  The last overload gave the following error.
    Argument of type 'DefineComponent<{ bar: BooleanConstructor; baz: StringConstructor; }, () => VNode<RendererNode, RendererElement, { [key: string]: any; }>, ... 9 more ..., { ...; }>' is not assignable to parameter of type 'ComponentOptionsWithObjectProps<readonly string[] | Readonly<ComponentObjectPropsOptions<Record<string, unknown>>>, () => VNode<RendererNode, RendererElement, { ...; }>, ... 8 more ..., { ...; } | {}>'.
      Property 'props' is missing in type 'ComponentPublicInstanceConstructor<{ $: ComponentInternalInstance; $data: {}; $props: Partial<{ bar: boolean; }> & Pick<Readonly<{ bar: boolean; } & { baz?: string; }> & VNodeProps & AllowedComponentProps & ComponentCustomProps, "baz" | ... 9 more ... | "style">; ... 10 more ...; $watch(source: string | Function, cb...' but required in type '{ props: (readonly string[] & ThisType<void>) | (Readonly<ComponentObjectPropsOptions<Record<string, unknown>>> & ThisType<void>); }'.ts(2769)

Here are the versions I'm using

"@vue/test-utils": "^2.0.0-beta.8",
"vue": "^3.0.2",

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions