Skip to content

Instantly share code, notes, and snippets.

@karol-majewski
Created March 15, 2019 01:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karol-majewski/9d4607ec1f88928c43ac76b7f6d79dbe to your computer and use it in GitHub Desktop.
Save karol-majewski/9d4607ec1f88928c43ac76b7f6d79dbe to your computer and use it in GitHub Desktop.
Typed React children
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