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

Add generic typing ability #8

Open
flextremedev opened this issue Jun 16, 2020 · 0 comments
Open

Add generic typing ability #8

flextremedev opened this issue Jun 16, 2020 · 0 comments

Comments

@flextremedev
Copy link
Owner

flextremedev commented Jun 16, 2020

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;
}
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

No branches or pull requests

1 participant