I have the following code used for run time type checking by vue.js
props: {
foo: Object | Array
}
Here Object and Array are runtime objects, it is used to do type checking at runtime by vue.js. This doesn't actually work because | is interpreted as an arithmetic operator since Object and Array are values rather than types.
Is there someway of constructing an object that can represent the object or array type?
You can do
props: {
foo: {
type: [Object, Array]
}
}
or more generally
props: {
foo: {
type: [Object as () => YourTypeScriptType, Array, String]
}
}
It will be like
type FooProps = YourTypeScriptType | Array | string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With