nuxtlabs / nuxt-component-meta

Gather Nuxt components metadata on build time and make them available on production.
73 stars 8 forks source link

Feature Request: Include default value for props #57

Closed AbdallahAlhaddad closed 1 year ago

AbdallahAlhaddad commented 1 year ago

Feature description:

Demo Code:

type ClrVariants = 'primary' | 'secondary'

interface TooltipProps {
  /**
   * Color variant to choose from, see ...
   */
  color?: ClrVariants
  text: string
}

const { color = 'primary', text } = defineProps<TooltipProps>()

Api Response:

{
  // ...
  "meta": {
    "props": [
      {
        "name": "text",
        "global": false,
        "description": "",
        "tags": [],
        "required": true,
        "type": "string",
        "declarations": [
          {
            "file": "nuxt-proj-absoulte-path/components/Tooltip.vue",
            "range": [290, 302]
          }
        ],
        "schema": "string"
      },
      {
        "name": "color",
        "global": false,
        "description": "Color variant to choose from, see ...",
        "tags": [],
        "required": false,
        "default": "primary", //  πŸ‘ˆ this field.
        "type": "ClrVariants | undefined",
        "declarations": [
          {
            "file": "nuxt-proj-absoulte-path/components/Tooltip.vue",
            "range": [268, 287]
          }
        ],
        "schema": {
          "kind": "enum",
          "type": "ClrVariants | undefined",
          "schema": ["undefined", "\"primary\"", "\"secondary\""]
        }
      }
    ]
    // ...
  }
}
AbdallahAlhaddad commented 1 year ago

If we use withDefaults it will be determined correctly

const { color, text } = withDefaults(defineProps<TooltipProps>(), {
  color: 'primary',
})
adamdehaven commented 3 weeks ago

With the new props destructuring, is it possible to update to still determine the default value without needing withDefaults?