shuding/nextra

`components` theme configuration to accept generic

Open

#1978 aperta il 18 giu 2023

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)TypeScript (1413 fork)user submission
enhancementgood first issue

Metriche repository

Star
 (13.807 star)
Metriche merge PR
 (Merge medio 6g 16h) (3 PR mergiate in 30 g)

Descrizione

Hi 👋

Context

I would like to create a custom component to be reusable inside all the documentation 😍

type IframeProps = {
  url: string;
};

export const Iframe: FunctionComponent<IframeProps> = ({ url }) => {
  return <iframe src={url} allowFullScreen className={styles.main} />;
};

Problem

Regarding the following documentation 👀

Capture d’écran 2023-06-18 à 09 57 24

In the code, type is define as components?: Record<string, FC> | undefined; but it's a little bit to strict because we can't pass any additional props.

Cannot assign type 'FC<OptionTableProps>' to type 'FC'.
  Parameter types 'props' and 'props' are incompatible.
    Unable to assign type '{}' to type 'OptionTableProps'. ts(2322)

Proposal solution

What about the possibility to accept a generic to pass additional props ? Is there any side effect for this improvement ?

components?: Record<string, FC<T>> | undefined;

I could open a PR if needed to support 😇 Thanks for it 🙏

Guida contributor