Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to get type description string like TypeScript type #1626

Open
zhuscat opened this issue Nov 22, 2023 · 2 comments
Open

Is it possible to get type description string like TypeScript type #1626

zhuscat opened this issue Nov 22, 2023 · 2 comments
Labels

Comments

@zhuscat
Copy link

zhuscat commented Nov 22, 2023

vue-docgen-api version: 4.75.1

Here is my code for test:

import vueDocs from 'vue-docgen-api'
var componentInfo
vueDocs
  .parseSource(
    `
<template></template>
<script setup lang="ts">
defineProps<{
  a: number | string
}>()
</script>
`,
    '/test.vue',
  )
  .then((ci) => {
    componentInfo = ci
    console.log(ci.props[0])
  })

The output is:

{
  name: 'a',
  required: true,
  type: { name: 'union', elements: [ { name: 'number' }, { name: 'string' } ] }
}

Is there a way I can get type description like number | string?

@elevatebart
Copy link
Member

Hello @zhuscat ,
I am not sure how to change this behavior without a breaking change, which I try to avoid at all costs. Major versions are not cheap.
You should probably add a customization layer between your code and the library.
The rule could be: If it's a union and there is only known types format it like typescript else let the engine format it

I think volar and the vue-component-meta package, though a bit slower, would help you in this a lot.

@elevatebart elevatebart added this to To Do in vue-docgen-cli via automation Nov 22, 2023
@zhuscat
Copy link
Author

zhuscat commented Nov 23, 2023

@elevatebart Thank you very much. You helped me a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
vue-docgen-cli
  
To Do
Development

No branches or pull requests

2 participants