Created
July 20, 2020 15:26
-
-
Save gsasouza/3c6aee09819d74197aca49618411bb3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const StyledGenericComponent = styled.div``; | |
type GenericProps<T> = { | |
as?: React.FC<T> | |
//...otherProps | |
} | |
const GenericComponent = <T>({ as, ...props }: Props<T> & T) => { | |
// some logic | |
return <StyledGenericComponent as={as} {...props}/> | |
} | |
const UseExample = () => ( | |
<> | |
<GenericComponent<{ prop1: number }> | |
prop1={1} | |
prop2={3} // type checker shows an error | |
/> | |
<GenericComponent<{}> | |
prop1={1} // type checker shows an error (prop1 doens't exist e Prop) | |
/> | |
<GenericComponent | |
prop1={1} // type check doesn't shows an error (prop1 doens't exist e Prop) | |
/> | |
</> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment