Boolean props shorthand does not work on components typescript defineprops
Version
3.2.31
Reproduction link
Steps to reproduce
see console.log tile is '' not true
What is expected?
true
What is actually happening?
''
That's because you define the prop in a way the compiler can not understand.
See docs: https://vuejs.org/api/sfc-script-setup.html#type-only-props-emit-declarations
As of now, the type declaration argument must be one of the following to ensure correct static analysis:
- A type literal
- A reference to an interface or a type literal in the same file
yours is neither - it's reading a property from an interface, and the compiler is not yet smart/complex enough to evaluate that.
@LinusBorg is there any method for me to link it to a outside interface? because I need interface to constrain other code ,and I want there are only one interface
Only the "normal" way to define props: with an actual object:
const props = defineProps({
tile: {
type: Boolean as PropType<BadgeProps['tile']>; // the casting is unnecessary here as `tile` is already of a primitive type.
}
})