(typescript) Required prop can be undefined when props is declared outside `defineComponent`
Version
3.0.5
Reproduction link
https://codesandbox.io/s/loving-frost-l1gox?file=/src/index.ts
Steps to reproduce
follow the link
What is expected?
props.requiredValue shouldn't be inferred as undefined.
What is actually happening?
Opposite
When declaring it outside you need as const
:
const props = {
requiredValue: {
type: Array as PropType<string[]>,
required: true
}
} as const;
Hi, sorry to comment this closed issue but I can't find a way to send props to a custom defineComponent
function, e.g. :
import { defineComponent } from 'vue'
export const props = {
msg: {
type: String,
required: true
}
} as const
function customComponent(props: {}) {
return defineComponent({
props
})
}
export default customComponent(props)
Is there any way to do that easily without using a custom DefineComponent type (I tried but without success for the moment) ?
Well, it was not so difficult (thanks to pikax on discord) :
function customComponent<P extends Readonly<ComponentPropsOptions> = {}>(
props: P
) {
return defineComponent({
extends: Parent,
props
})
}
Just another component : https://v3.vuejs.org/api/options-composition.html#extends