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

TsInfo improvements #33

Closed
cristatus opened this issue Jun 23, 2021 · 1 comment · May be fixed by #34
Closed

TsInfo improvements #33

cristatus opened this issue Jun 23, 2021 · 1 comment · May be fixed by #34

Comments

@cristatus
Copy link

Consider the following case:

type Variant = "primary" | "secondary";

type Size = "sm" | "md" | "lg";

type Dimension = {
  w?: number;
  h?: number;
}

interface AsProp {
  as?: any;
}

interface BaseProps {
  size?: Size;
  wh?: Dimension;
}

interface ButtonProps extends BaseProps, AsProp {
  variant?: Variant | "link";
}

The TsInfo should show following output:

Name Description Type Default Value
variant "primary" | "secondary" | "link"
size "sm" | "md" | "lg"
wh { w: number, h: number }
as any

What I am getting:

Name Description Type Default Value
variant Variant | "link"

Suggested improvements:

  1. expand type references
  2. expand heritage clauses
  3. allow to skip certain heritage types

Examples:

  1. <TsInfo src="./Button.tsx" name="ButtonProps"/> should expand ButtonProps only no heritage types
  2. ` should expand inherited props too
  3. <TsInfo src="./Button.tsx" name="ButtonProps" heritage="AsProp"/> should expand inherited props from AsProp and not all (can be comma separated names).

And the jsx api should be like:

import _TsInfo0 from './types.ts?tsInfo=ButtonProps'

import _TsInfo0 from './types.ts?tsInfo=ButtonProps&heritage=true'

import _TsInfo0 from './types.ts?tsInfo=ButtonProps&heritage=AsProp'
@cristatus
Copy link
Author

Alternative syntax can be:

// only local props
<TsInfo src="./Button.tsx" name="ButtonProps"/>

// with all inherited props
<TsInfo src="./Button.tsx" name="ButtonProps:*"/>

// only local props & props from AsProp
<TsInfo src="./Button.tsx" name="ButtonProps:AsProp"/>

cristatus added a commit to cristatus/vite-plugin-react-pages that referenced this issue Jun 23, 2021
Now expands type aliases and interfaces with literal only types.
Also allows to expand inherited props.

Example:

```mdx
<TsInfo src='./Button.tsx' name='ButtonProps'` />
<TsInfo src='./Button.tsx' name='ButtonProps:*'` />
<TsInfo src='./Button.tsx' name='ButtonProps:AsProp'` />
<TsInfo src='./Button.tsx' name='ButtonProps:AsProp:BaseProps'` />
```

Fixes vitejs#33
@csr632 csr632 closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants