Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

defineProps({
 
})

How other developer define props

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

defineProps<({
 
})>()

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.

>Solution :

The difference is the language (Javascript / TypeScript).

JS (weakly typed):

<script setup>
const props = defineProps({
  foo: String,
  bar: Number
})
</script>

TS (strongly typed):

<script setup lang="ts">
const props = defineProps<{
  foo: string
  bar?: number
}>()
</script>

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading