Skip to content

Add generic typing ability #8

@flextremedev

Description

@flextremedev

Provide an API for checking more specific components via Props and/or State.
For example:

let maybeFC: React.FC<{foo: string}> | string = ({foo}) => <div>{`${foo}, I'm a function component!`}</div>;
if (Math.random() > 0.5) {
  maybeFC = 'Not FC';
}
if (isFunctionComponent<{foo: string}>(maybeFC)) {
  const fcWithProps: React.FC<{foo: string}> = maybeFC;
  const FCWithProps = fcWithProps;
  const fcWithPropsElem = <FCWithProps foo='bar'}/>; // should not have a type error
} else {
  const notFC: string = maybeFC;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions