Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error when mounting component with boolean prop #237

Closed
nekosaur opened this issue Nov 5, 2020 · 2 comments · Fixed by #274
Closed

Typescript error when mounting component with boolean prop #237

nekosaur opened this issue Nov 5, 2020 · 2 comments · Fixed by #274

Comments

@nekosaur
Copy link
Contributor

nekosaur commented Nov 5, 2020

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",
@lmiller1990
Copy link
Member

Same as #194 I think 🤔

@lmiller1990
Copy link
Member

lmiller1990 commented Nov 8, 2020

Seems to be a mismatch between JS Boolean and TS boolean. Casting it works (we should fix it, but work around + might help someone debug this).

const Foo = defineComponent({
  name: 'Foo',
  props: {
    bar: Boolean as () => boolean,
    baz: String,
  }
})

I have absolutely no idea how to even start debugging this :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants