Skip to content

Instantly share code, notes, and snippets.

@danakt
Created June 27, 2019 17:25
Show Gist options
  • Save danakt/7771808d40b9c1e2ef49fff66326f3e8 to your computer and use it in GitHub Desktop.
Save danakt/7771808d40b9c1e2ef49fff66326f3e8 to your computer and use it in GitHub Desktop.
Returns type of HTML element by tag name
/**
* Returns type of HTML element by tag name
* @example
* type ElementType = GetElementByTagname<'div'> // HTMLDivElement
*/
type GetElementByTagName<
Tagname extends keyof React.ReactHTML
> = React.ReactHTML[Tagname] extends React.DetailedHTMLFactory<infer A, infer E> ? E : null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment