From 5eb6dbca864b7333fa551cfb9772ad8b2c8ddd17 Mon Sep 17 00:00:00 2001 From: Sergey Sova <5620073+sergeysova@users.noreply.github.com> Date: Fri, 5 Jun 2020 08:17:47 +0300 Subject: [PATCH] Make the TypeScript type a union of the HTML tags (#5) Co-authored-by: Sindre Sorhus --- index.d.ts | 124 ++++++++++++++++++++++++++++++++++++++++++++++-- index.test-d.ts | 3 +- 2 files changed, 123 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6415096..457891d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,122 @@ +export type HTMLTags = + | 'a' + | 'abbr' + | 'address' + | 'area' + | 'article' + | 'aside' + | 'audio' + | 'b' + | 'base' + | 'bdi' + | 'bdo' + | 'blockquote' + | 'body' + | 'br' + | 'button' + | 'canvas' + | 'caption' + | 'cite' + | 'code' + | 'col' + | 'colgroup' + | 'data' + | 'datalist' + | 'dd' + | 'del' + | 'details' + | 'dfn' + | 'dialog' + | 'div' + | 'dl' + | 'dt' + | 'em' + | 'embed' + | 'fieldset' + | 'figcaption' + | 'figure' + | 'footer' + | 'form' + | 'h1' + | 'h2' + | 'h3' + | 'h4' + | 'h5' + | 'h6' + | 'head' + | 'header' + | 'hgroup' + | 'hr' + | 'html' + | 'i' + | 'iframe' + | 'img' + | 'input' + | 'ins' + | 'kbd' + | 'label' + | 'legend' + | 'li' + | 'link' + | 'main' + | 'map' + | 'mark' + | 'math' + | 'menu' + | 'menuitem' + | 'meta' + | 'meter' + | 'nav' + | 'noscript' + | 'object' + | 'ol' + | 'optgroup' + | 'option' + | 'output' + | 'p' + | 'param' + | 'picture' + | 'pre' + | 'progress' + | 'q' + | 'rb' + | 'rp' + | 'rt' + | 'rtc' + | 'ruby' + | 's' + | 'samp' + | 'script' + | 'section' + | 'select' + | 'slot' + | 'small' + | 'source' + | 'span' + | 'strong' + | 'style' + | 'sub' + | 'summary' + | 'sup' + | 'svg' + | 'table' + | 'tbody' + | 'td' + | 'template' + | 'textarea' + | 'tfoot' + | 'th' + | 'thead' + | 'time' + | 'title' + | 'tr' + | 'track' + | 'u' + | 'ul' + | 'var' + | 'video' + | 'wbr'; + /** List of standard HTML tags. @@ -9,6 +128,5 @@ console.log(htmlTags); //=> ['a', 'abbr', 'acronym', …] ``` */ -declare const htmlTags: readonly string[]; - -export = htmlTags; +declare const htmlTags: HTMLTags[]; +export default htmlTags; diff --git a/index.test-d.ts b/index.test-d.ts index 28fc5df..3700363 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,9 +1,10 @@ import {expectType, expectError} from 'tsd'; -import htmlTags = require('.'); +import htmlTags, {HTMLTags} from '.' import voidHtmlTags = require('./void'); import htmlTagsJson = require('./html-tags.json'); import voidHtmlTagsJson = require('./html-tags-void.json'); +expectType(htmlTags); expectType(htmlTags); expectError(htmlTags.push('')); expectType(voidHtmlTags);