Skip to content

Instantly share code, notes, and snippets.

@danakt
Last active August 30, 2018 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danakt/c9d64afe5f63c0482d534d0a85c563fb to your computer and use it in GitHub Desktop.
Save danakt/c9d64afe5f63c0482d534d0a85c563fb to your computer and use it in GitHub Desktop.
Expanding attributes of JSX element
/// <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