question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better typings in props mounting options

See original GitHub issue

Currently we have pretty good typings. But there are some limitations.

If there is a ts file that exports defineComponent, all is well. For example:

const Foo = defineComponent({
  props: {
    bar: { type: String }
  }
})

// in a test

mount(Foo, {
  props: {
    bar: 123 // ide warning! bar should be a string
  }
})

However we cannot get this level of type safety when importing a vue. file, since it’s not a regular TS file (needs to be parsed by SFC compiler first), or at least this is the case with this kind of simple shim:

declare module '*.vue' {
  import { ComponentOptions } from 'vue'
  var component: ComponentOptions
  export default component
}

What are our options? 🤔

  1. some kind of language server like vue-developer-experience
  2. Export interface Props from the SFC and make mount take a generic param? Eg mount<Props>(...). Not really ideal but an option we can consider.
  3. ???

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lmiller1990commented, Jun 1, 2020

The other workaround would be to define your component in a ts file, then

<script lang="ts" src="./component.ts">

in your vue file - not ideal, but honestly not terrible, at least for until the tooling matures.

0reactions
lmiller1990commented, Aug 12, 2020

I do not think there is much else we can do in VTU for this. Some kind of dev server wlil be needed, which is outside the scope of VTU atm. This is explored more here: https://github.com/znck/vue-developer-experience

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better typings in props mounting options · Issue #97 - GitHub
Currently we have pretty good typings. But there are some limitations. If there is a ts file that exports defineComponent, all is well....
Read more >
Defining Props in React Function Component with Typescript
Introduction. This guide will provide you with the syntax you need to properly define the props entering your components, compare and contrast ...
Read more >
Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >
Comparing TypeScript and PropTypes in React applications
Compare TypeScript and PropTypes, tools for type checking, to determine which one best suits your project's needs.
Read more >
How To Customize React Components with Props
In this tutorial, you'll create custom components by passing props to your component. Props are arguments that you provide to a JSX element....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found