vite-plugin-react-pages icon indicating copy to clipboard operation
vite-plugin-react-pages copied to clipboard

TsInfo improvements

Open cristatus opened this issue 3 years ago • 1 comments

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. `<TsInfo src="./Button.tsx" name="ButtonProps" heritage="true"/> 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 avatar Jun 23 '21 07:06 cristatus

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 avatar Jun 23 '21 07:06 cristatus