Last active
June 8, 2020 12:33
-
-
Save janjakubnanista/8a09e192d10f33c2ea41e8ed01f6d6b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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