Created
March 15, 2019 01:02
-
-
Save karol-majewski/9d4607ec1f88928c43ac76b7f6d79dbe to your computer and use it in GitHub Desktop.
Typed React children
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
interface OptionProps { | |
id: string; | |
} | |
interface SelectProps { | |
children: React.FunctionComponentElement<OptionProps>[] | |
} | |
declare const Option: React.FC<OptionProps>; | |
declare const Select: React.FC<SelectProps>; | |
/** | |
* All these give compile-time errors. | |
*/ | |
<Select></Select> | |
<Select><div>Hello</div></Select> | |
<Select>1</Select> | |
<Select><Option id="42"/></Select> | |
/** | |
* Works as expected. | |
*/ | |
<Select> | |
<Option id="1" /> | |
<Option id="2" /> | |
</Select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment