Skip to content

defineProps with Typescript type always infer props to "null" #7629

Closed as not planned
@Kapcash

Description

@Kapcash

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>, the defineProps<PropsType> function does not infer correct props attributes from the Typescript type. It always generate props being null.

  1. Create a Typescript type for some props. For instance:
interface PropsType {
     foo: string;
     bar?: number;
}
  1. Use this type in the defineProps generic type: defineProps<PropsType>()
  2. Take a look at the props object in the transpiled code

What is expected?

The transpiled props object should be

props: {
    foo: { type: String, required: true },
    bar: Number
},

What is actually happening?

This is what is generated since v3.2.20 (it's working fine before that version)

props: {
   foo: null,
   bar: null
},

System Info

N/A

Any additional comments?

You can switch between versions on the playground to see it's a regression from version v3.2.20.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions