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

Generation documentation of imported prop types #1590

Closed
sevilyilmaz opened this issue Jul 26, 2023 · 4 comments · Fixed by #1592
Closed

Generation documentation of imported prop types #1590

sevilyilmaz opened this issue Jul 26, 2023 · 4 comments · Fixed by #1592
Labels
enhancement New feature or request

Comments

@sevilyilmaz
Copy link
Contributor

The problem

I import the prop types from another file. Therefore styleguidist does not read the documentation that are written there. Containing types in the SFCs might be fine with the simple ones. But when the component has many props or complex types it pollutes the file and it becomes a common practice to put the types in a separate file.

// MyComponent.types
export type Props = {
  /**
   * This prop does things
   */
  myProp?: string;

  /**
   * This prop does cool things
   */
  myOtherCoolProp?: SomeComplexTypeDefinedInThisFile
}
// MyComponent.vue
import type * as T from './MyComponent.types'

// This won't read the comments from the imported types
const props = defineProps<T.Props>();

Proposed solution

I don't have any proposal, sorry.

Alternative solutions

None

Additional context

Since Vue also started to support the imported types on SFC macros it can be a common way to move the types in their own file.

@elevatebart elevatebart added the enhancement New feature or request label Jul 26, 2023
@elevatebart elevatebart added this to todo in vue-docgen-api via automation Jul 26, 2023
@elevatebart
Copy link
Member

I simply will start redirecting people to a library that takes another approach:

vue-component-meta

Upside: all will work with TypeScript.
Downside: Adding a description to a slot and its bindings is impossible.

@sevilyilmaz
Copy link
Contributor Author

sevilyilmaz commented Jul 26, 2023

I really like how flexible vue-docgen-api is. Using vue-compoenent-meta will mean that I will need to use both. But in any case, thank you for the pointer.

Edit: I just saw this PR got merged. I'll give it another try.
Edit 2: It didn't work

@sevilyilmaz
Copy link
Contributor Author

@elevatebart with the PR above actually works. The docgen was able to extract the documentation when I imported the types separately but it didn't work when I imported all of them. Here are examples, in case there is an easy fix:

// works
import type { Props } from './Component.types';
const props = withDefaults(defineProps<Props>(), { size: 'medium' })

// doesn't work
import type * as T from './Component.types';
const props = withDefaults(defineProps<T.Props>(), { size: 'medium' })

@elevatebart
Copy link
Member

OOOh I understand !!

Well yeah that should be possible. I am going to create a quick repro on a branch, see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

2 participants