playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Derive the prop type from the Vue/Svelte component

Open sand4rt opened this issue 3 years ago • 1 comments

Would be great if the type of prop could be derived from the component (mount(Component)) instead of explicitly defining it through the generic (mount<Props>). Vue test utils also managed to do this: https://github.com/vuejs/test-utils/blob/main/test-dts/mount.d-test.ts#L60.

<script lang="ts" setup>
  defineProps<{ title: string }>();
</script>
<template>
  <button>{{ title }}</button>
</template>
test('should not work', async ({ mount }) => {
  await mount(Button, { props: {} }) // Should throw a type error because title is a required prop
})
  • [x] Svelte
  • [ ] Vue 3
  • [ ] Vue 2

sand4rt avatar Sep 08 '22 21:09 sand4rt

Vue released some type helpers that could solve this issue: https://www.npmjs.com/package/vue-component-type-helpers

sand4rt avatar May 06 '23 20:05 sand4rt