[defineComponent type error ] when use props validator
Version
3.2.2
Reproduction link
Steps to reproduce
SFC-type-error :
<template>
{{ direction }}
</template>
<script lang="ts">
import { defineComponent } from "vue";
import type { PropType } from "vue";
type Align = "x" | "y";
export default defineComponent({
props: {
direction: {
type: String as PropType<Align>,
default: "y",
validator(direction: Align) {
return ["x", "y"].includes(direction);
},
},
},
setup(props) {
// type error notice here
console.log(props.direction);
return {};
},
});
</script>
SFC -no-type-error:
<template>
{{ direction }}
</template>
<script lang="ts">
import { defineComponent } from "vue";
import type { PropType } from "vue";
type Align = "x" | "y";
export default defineComponent({
props: {
direction: {
type: String as PropType<Align>,
default: "y",
validator:(direction: Align) =>{
return ["x", "y"].includes(direction);
},
},
},
setup(props) {
// type error notice here
console.log(props.direction);
return {};
},
});
</script>
What is expected?
no type error notice
What is actually happening?
type error notice
validator(this:void, direction: Align) {
return ["x", "y"].includes(direction);
},
see https://v3.vuejs.org/guide/typescript-support.html#annotating-props