Better typings in props mounting options
See original GitHub issueCurrently 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? 🤔
- some kind of language server like vue-developer-experience
- Export
interface Props
from the SFC and makemount
take a generic param? Egmount<Props>(...)
. Not really ideal but an option we can consider. - ???
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The other workaround would be to define your component in a
ts
file, thenin your
vue
file - not ideal, but honestly not terrible, at least for until the tooling matures.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