Skip to content
Advertisement

Difference between defineProps() and defineProps({ }) syntax?

Actually, I read someone code and they define props using defineProps<({})>() syntax and I research about it and didn’t find anything which helps me to understand about this syntax.

How I Define Props

JavaScript

How other developer define props

JavaScript

I want to know what’s the difference between both syntax.

Thanks in Advance

I actually don’t know about two different syntax of defining props in Vue 3 script setup. So, I’ve tried to ask a question so that I can understand about both syntaxes.

Advertisement

Answer

The difference is the language (Javascript / TypeScript).

JS (weakly typed):

JavaScript

TS (strongly typed):

JavaScript

So in TypeScript you need to tell the type, while in JavaScript you don’t.

Related docs: https://vuejs.org/guide/typescript/composition-api.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement