Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save janjakubnanista/8a09e192d10f33c2ea41e8ed01f6d6b5 to your computer and use it in GitHub Desktop.
Save janjakubnanista/8a09e192d10f33c2ea41e8ed01f6d6b5 to your computer and use it in GitHub Desktop.
// Approach 3: the light at the end of the tunnel
//
// TypeScript 3.7 introduced "assertion functions" that
// allow us to define an assertion function.
// We might use such function to ensure that anything we pass to it is a React.FC
// while writing no code whatsoever! BINGO!
function assertFC<P>(component: React.FC<P>): asserts component is React.FC<P> {
// We don't need to do anything here because the assertion happens
// on the type level - we need to pass a valid React component
}
// Then we use it in our Select component
function Select<T>(props: SelectProps<T>): React.ReactElement | null {
return null;
}
assertFC(Select);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment