Subscribe on changes!

defineProps is not compiled in a nested scope in SFC script setup

avatar
Aug 29th 2021

Version

3.2.6

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Call defineProps in a script setup SFC file in a scope that is not at the top level.

What is expected?

defineProps should be compiled to __props

What is actually happening?

defineProps is called at runtime causing a ReferenceError


Implementation like the repo example is useful when defining a component with generic props

avatar
Aug 30th 2021

defineEmits() is a macro, it needs to be able to statically analyze what is passed to it in order to know what to generate, so it doesn't seem reasonable to be used that way as it doesn't get called in reality, even less with a generic T that is never given any type.

Maybe you are looking for this: https://github.com/vuejs/vue-next/pull/3682

avatar
Aug 30th 2021

@posva That PR does seem like it would be a possible solution for what I'm looking for. But since that's using the defineComponent api, is there any guidance on being able to define components with generic props using the <script setup> syntax?