Last active
August 30, 2018 16:28
-
-
Save danakt/c9d64afe5f63c0482d534d0a85c563fb to your computer and use it in GitHub Desktop.
Expanding attributes of JSX element
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
/// <reference path="../node_modules/@types/react/index.d.ts" /> | |
/** | |
* Enhancer of JSX attributes | |
*/ | |
type EnhanceAttributes< | |
Tagname extends keyof React.ReactHTML, | |
NewAttributes extends {}, | |
T = React.ReactHTML[Tagname] | |
> = T extends React.DetailedHTMLFactory<infer A, infer E> | |
? React.DetailedHTMLProps<A, E> & NewAttributes | |
: null; | |
/** | |
* Expanding attributes of JSX <table> element for example | |
*/ | |
declare namespace JSX { | |
interface IntrinsicElements { | |
table: EnhanceAttributes< | |
'table', | |
{ border?: number; bgcolor?: string; width?: string } | |
>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment