Created
June 4, 2020 15:42
-
-
Save janjakubnanista/3346b1bd31cac81680fea0db4fdafb3a 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 2: diving back in looking for a better way | |
// | |
// We can create a type that accepts a type parameter | |
// and puts a constraint on it, in our case we will demand | |
// the type parameter to be a React.FC | |
type AssertComponent<C extends React.FC<any>> = C; | |
// Then we use it in our Select component | |
function Select<T>(props: SelectProps<T>) { | |
return null; | |
} | |
// If the Select does not look like a React component, this line will trigger an error | |
type AssertSelect = AssertComponent<typeof Select>; | |
// However we ended up with an unused type AssertSelect :( | |
// And we can still pass invalid defaultProps :((( | |
Select.defaultProps = 7; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment