You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vetur's template interpolation feature is great, it typechecks the javascript expressions that appear in the <template> section of a single-file component. This includes the values passed to v-for and v-if, as well as the properties passed to other components.
There are two things missing though:
it doesn't check that a components exists and is registered in the first place, and
it doesn't check that the component receives all the required props, or that the values passed as props to the component have the right type for that prop.
I'm not sure what is required for this to work, and it may take a coordinated effort with the vue project to get access to components' types in the code that vetur generates. This is a necessary requirement though, for vetur templates to be just as type-safe as JSX.
Reproducible Case
<!-- ComponentA.vue --><template><div><pv-if="x > 5">{{ x }} is greater than 5</p><pv-if="x === 5">{{ x }} is equal to 5</p><pv-if="x < 5">{{ x }} is less than 5</p></div></template><scriptlang="ts">
import Vue from "vue";
export default Vue.extend({
props: {
x: {
type: Number,
required: true,
},
},
});
<!-- ComponentB.vue --><template><div><!-- this should be an error, because `theNumber` is a string, and `ComponentA` expects `x` to be a number --><ComponentA:x="number" /></div></template><scriptlang=ts>importVuefrom"vue";exportdefaultVue.extend({data(){return{theNumber: "four",};},});</script>
The text was updated successfully, but these errors were encountered:
We do plan to implement this feature. There are a few problem on the way though.
The current prop type is not accurate - it does not handle required option and won't appear on type level. It's already solved in Vue 3 implementation.
We need to collect component type and its registered name from components options.
Info
Problem
Vetur's template interpolation feature is great, it typechecks the javascript expressions that appear in the
<template>
section of a single-file component. This includes the values passed tov-for
andv-if
, as well as the properties passed to other components.There are two things missing though:
I'm not sure what is required for this to work, and it may take a coordinated effort with the vue project to get access to components' types in the code that vetur generates. This is a necessary requirement though, for vetur templates to be just as type-safe as JSX.
Reproducible Case
The text was updated successfully, but these errors were encountered: