-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
defineProps with Typescript type always infer props to "null" #7629
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Type verification is performed only in the development environment and not in the production environment. So the production environment type is changed to null. |
Two questions related to this issue:
|
The compiler should actually not create such an output. it should create this: props: {
msg: { type: String, required: true },
labels: { type: Array, required: false }
}, Thing is: I copied this code from the compiled output for that component when pasted into a real vite projects using the latest version of Vue. So it seems this is a Playground problem, but not sure if related to the issue @edison1105 linked? |
@LinusBorg const props = defineProps<{msg: string}>()
// compiled code is:
props: {
msg: null
} so I feel this is by design. |
This is a problem for component libraries that are used in non TS projects, since after building components don't complain about missing required props. What should I do for consumers to know that there are missing props? |
Closing as this is by design. |
What's the actual benefit of removing this prop type runtime check in production? Is it purely for performance and bundle size? Otherwise, maybe it's not worth removing this as it would impact component library usage and confuse users like me regarding the missing checks haha |
Vue version
v3.2.20
Link to minimal reproduction
https://sfc.vuejs.org/#eNp9Uk2P0zAQ/SuDLylSG8NyIrTLIoG0h5VA2gOHNYe0maRmHdv4owVF+e+MnW2VLmgvlj1vZt74zRvYJ2vLQ0RWsbXfOWkDeAzRXgste2tcgAEctjBC60wPBaUWZ+gWlTJPQMnzK/WiBKF3RvsAve9gkxosiin5u3GqeVW8FnrNJz5iokfA3qo6IL0A1lNupeotKr8R7OGHYJygNT/nsSWbplj1tS1/eqPpC0OqFk+AF6yCHEkxmiu9BduHYH3FedT2sSt3puc3hHEXdZA9rhrT37wrr8qrN7yRPszjJfp+tXXm6NERo2DLWXNOwQO6lUPdoEP3Itmz3AvCZ9g/pIlzFHokAc6Kp+1dKtjIQ74A3H65u/sKw5B3MY7pNun6sVSou7CnYC4h+lQz0zhvZu4KqtQd7SNpSyj+zjaQOqBr6x3CN2esnzQntgp8cFJ3H4BzuN+bqBrYIhkq/LFYwX0Gl+SOX1E6bCoILiI5bRupp5866KjU5DASxUuj4TCJBYt8efs+pR6Ne6Re0EqNZC04/fA0AflH0ydPrrR5zA00mAry0Ot8Xi+oWmga9zLxKMP+M7Z1VMEv/le1TJ+mshNzBQ+FsYHmrVVB5ASNc8+z8S/y8zJ8
Steps to reproduce
Using
<script setup lang="ts>
, thedefineProps<PropsType>
function does not infer correct props attributes from the Typescript type. It always generate props beingnull
.defineProps
generic type:defineProps<PropsType>()
What is expected?
The transpiled props object should be
What is actually happening?
This is what is generated since v3.2.20 (it's working fine before that version)
System Info
Any additional comments?
You can switch between versions on the playground to see it's a regression from version v3.2.20.
The text was updated successfully, but these errors were encountered: