Create typeof's string literal union type once

This changes the print order of string literal unions slightly. I think
this is because 'string', 'symbol', etc are added to a union very early
on in the creation of the checker.
This commit is contained in:
Nathan Shively-Sanders 2017-01-31 14:39:10 -08:00
parent 01bc4efc82
commit 2ce64f2bad
3 changed files with 10 additions and 7 deletions

View File

@ -326,7 +326,6 @@ namespace ts {
"object": TypeFacts.TypeofEQObject,
"function": TypeFacts.TypeofEQFunction
});
const typeofNEFacts = createMapFromTemplate({
"string": TypeFacts.TypeofNEString,
"number": TypeFacts.TypeofNENumber,
@ -336,7 +335,6 @@ namespace ts {
"object": TypeFacts.TypeofNEObject,
"function": TypeFacts.TypeofNEFunction
});
const typeofTypesByName = createMapFromTemplate<Type>({
"string": stringType,
"number": numberType,
@ -344,6 +342,7 @@ namespace ts {
"symbol": esSymbolType,
"undefined": undefinedType
});
const typeofType = createTypeofType();
let jsxElementType: Type;
let _jsxNamespace: string;
@ -1725,6 +1724,10 @@ namespace ts {
return type;
}
function createTypeofType() {
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
}
// A reserved member name starts with two underscores, but the third character cannot be an underscore
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
@ -14609,7 +14612,7 @@ namespace ts {
function checkTypeOfExpression(node: TypeOfExpression): Type {
checkExpression(node.expression);
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
return typeofType;
}
function checkVoidExpression(node: VoidExpression): Type {

View File

@ -227,9 +227,9 @@ function getValueAsString(value: IntersectionFail): string {
if (value.kind === 'int') {
>value.kind === 'int' : boolean
>value.kind : "int" | "string"
>value.kind : "string" | "int"
>value : IntersectionFail
>kind : "int" | "string"
>kind : "string" | "int"
>'int' : "int"
return '' + value.num;

View File

@ -3,9 +3,9 @@
for (const element of document.getElementsByTagName("a")) {
>element : HTMLAnchorElement
>document.getElementsByTagName("a") : NodeListOf<HTMLAnchorElement>
>document.getElementsByTagName : { <K extends "a" | "abbr" | "acronym" | "address" | "applet" | "area" | "article" | "aside" | "audio" | "b" | "base" | "basefont" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "circle" | "cite" | "clippath" | "code" | "col" | "colgroup" | "datalist" | "dd" | "defs" | "del" | "desc" | "dfn" | "dir" | "div" | "dl" | "dt" | "ellipse" | "em" | "embed" | "feblend" | "fecolormatrix" | "fecomponenttransfer" | "fecomposite" | "feconvolvematrix" | "fediffuselighting" | "fedisplacementmap" | "fedistantlight" | "feflood" | "fefunca" | "fefuncb" | "fefuncg" | "fefuncr" | "fegaussianblur" | "feimage" | "femerge" | "femergenode" | "femorphology" | "feoffset" | "fepointlight" | "fespecularlighting" | "fespotlight" | "fetile" | "feturbulence" | "fieldset" | "figcaption" | "figure" | "filter" | "font" | "footer" | "foreignobject" | "form" | "frame" | "frameset" | "g" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "image" | "img" | "input" | "ins" | "isindex" | "kbd" | "keygen" | "label" | "legend" | "li" | "line" | "lineargradient" | "link" | "listing" | "map" | "mark" | "marker" | "marquee" | "mask" | "menu" | "meta" | "metadata" | "meter" | "nav" | "nextid" | "nobr" | "noframes" | "noscript" | "object" | "ol" | "optgroup" | "option" | "p" | "param" | "path" | "pattern" | "picture" | "plaintext" | "polygon" | "polyline" | "pre" | "progress" | "q" | "radialgradient" | "rect" | "rt" | "ruby" | "s" | "samp" | "script" | "section" | "select" | "small" | "source" | "span" | "stop" | "strike" | "strong" | "style" | "sub" | "sup" | "svg" | "switch" | "symbol" | "table" | "tbody" | "td" | "template" | "text" | "textpath" | "textarea" | "tfoot" | "th" | "thead" | "title" | "tr" | "track" | "tspan" | "tt" | "u" | "ul" | "use" | "var" | "video" | "view" | "wbr" | "x-ms-webview" | "xmp">(tagname: K): ElementListTagNameMap[K]; (tagname: string): NodeListOf<Element>; }
>document.getElementsByTagName : { <K extends "symbol" | "object" | "a" | "abbr" | "acronym" | "address" | "applet" | "area" | "article" | "aside" | "audio" | "b" | "base" | "basefont" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "circle" | "cite" | "clippath" | "code" | "col" | "colgroup" | "datalist" | "dd" | "defs" | "del" | "desc" | "dfn" | "dir" | "div" | "dl" | "dt" | "ellipse" | "em" | "embed" | "feblend" | "fecolormatrix" | "fecomponenttransfer" | "fecomposite" | "feconvolvematrix" | "fediffuselighting" | "fedisplacementmap" | "fedistantlight" | "feflood" | "fefunca" | "fefuncb" | "fefuncg" | "fefuncr" | "fegaussianblur" | "feimage" | "femerge" | "femergenode" | "femorphology" | "feoffset" | "fepointlight" | "fespecularlighting" | "fespotlight" | "fetile" | "feturbulence" | "fieldset" | "figcaption" | "figure" | "filter" | "font" | "footer" | "foreignobject" | "form" | "frame" | "frameset" | "g" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "image" | "img" | "input" | "ins" | "isindex" | "kbd" | "keygen" | "label" | "legend" | "li" | "line" | "lineargradient" | "link" | "listing" | "map" | "mark" | "marker" | "marquee" | "mask" | "menu" | "meta" | "metadata" | "meter" | "nav" | "nextid" | "nobr" | "noframes" | "noscript" | "ol" | "optgroup" | "option" | "p" | "param" | "path" | "pattern" | "picture" | "plaintext" | "polygon" | "polyline" | "pre" | "progress" | "q" | "radialgradient" | "rect" | "rt" | "ruby" | "s" | "samp" | "script" | "section" | "select" | "small" | "source" | "span" | "stop" | "strike" | "strong" | "style" | "sub" | "sup" | "svg" | "switch" | "table" | "tbody" | "td" | "template" | "text" | "textpath" | "textarea" | "tfoot" | "th" | "thead" | "title" | "tr" | "track" | "tspan" | "tt" | "u" | "ul" | "use" | "var" | "video" | "view" | "wbr" | "x-ms-webview" | "xmp">(tagname: K): ElementListTagNameMap[K]; (tagname: string): NodeListOf<Element>; }
>document : Document
>getElementsByTagName : { <K extends "a" | "abbr" | "acronym" | "address" | "applet" | "area" | "article" | "aside" | "audio" | "b" | "base" | "basefont" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "circle" | "cite" | "clippath" | "code" | "col" | "colgroup" | "datalist" | "dd" | "defs" | "del" | "desc" | "dfn" | "dir" | "div" | "dl" | "dt" | "ellipse" | "em" | "embed" | "feblend" | "fecolormatrix" | "fecomponenttransfer" | "fecomposite" | "feconvolvematrix" | "fediffuselighting" | "fedisplacementmap" | "fedistantlight" | "feflood" | "fefunca" | "fefuncb" | "fefuncg" | "fefuncr" | "fegaussianblur" | "feimage" | "femerge" | "femergenode" | "femorphology" | "feoffset" | "fepointlight" | "fespecularlighting" | "fespotlight" | "fetile" | "feturbulence" | "fieldset" | "figcaption" | "figure" | "filter" | "font" | "footer" | "foreignobject" | "form" | "frame" | "frameset" | "g" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "image" | "img" | "input" | "ins" | "isindex" | "kbd" | "keygen" | "label" | "legend" | "li" | "line" | "lineargradient" | "link" | "listing" | "map" | "mark" | "marker" | "marquee" | "mask" | "menu" | "meta" | "metadata" | "meter" | "nav" | "nextid" | "nobr" | "noframes" | "noscript" | "object" | "ol" | "optgroup" | "option" | "p" | "param" | "path" | "pattern" | "picture" | "plaintext" | "polygon" | "polyline" | "pre" | "progress" | "q" | "radialgradient" | "rect" | "rt" | "ruby" | "s" | "samp" | "script" | "section" | "select" | "small" | "source" | "span" | "stop" | "strike" | "strong" | "style" | "sub" | "sup" | "svg" | "switch" | "symbol" | "table" | "tbody" | "td" | "template" | "text" | "textpath" | "textarea" | "tfoot" | "th" | "thead" | "title" | "tr" | "track" | "tspan" | "tt" | "u" | "ul" | "use" | "var" | "video" | "view" | "wbr" | "x-ms-webview" | "xmp">(tagname: K): ElementListTagNameMap[K]; (tagname: string): NodeListOf<Element>; }
>getElementsByTagName : { <K extends "symbol" | "object" | "a" | "abbr" | "acronym" | "address" | "applet" | "area" | "article" | "aside" | "audio" | "b" | "base" | "basefont" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "circle" | "cite" | "clippath" | "code" | "col" | "colgroup" | "datalist" | "dd" | "defs" | "del" | "desc" | "dfn" | "dir" | "div" | "dl" | "dt" | "ellipse" | "em" | "embed" | "feblend" | "fecolormatrix" | "fecomponenttransfer" | "fecomposite" | "feconvolvematrix" | "fediffuselighting" | "fedisplacementmap" | "fedistantlight" | "feflood" | "fefunca" | "fefuncb" | "fefuncg" | "fefuncr" | "fegaussianblur" | "feimage" | "femerge" | "femergenode" | "femorphology" | "feoffset" | "fepointlight" | "fespecularlighting" | "fespotlight" | "fetile" | "feturbulence" | "fieldset" | "figcaption" | "figure" | "filter" | "font" | "footer" | "foreignobject" | "form" | "frame" | "frameset" | "g" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "image" | "img" | "input" | "ins" | "isindex" | "kbd" | "keygen" | "label" | "legend" | "li" | "line" | "lineargradient" | "link" | "listing" | "map" | "mark" | "marker" | "marquee" | "mask" | "menu" | "meta" | "metadata" | "meter" | "nav" | "nextid" | "nobr" | "noframes" | "noscript" | "ol" | "optgroup" | "option" | "p" | "param" | "path" | "pattern" | "picture" | "plaintext" | "polygon" | "polyline" | "pre" | "progress" | "q" | "radialgradient" | "rect" | "rt" | "ruby" | "s" | "samp" | "script" | "section" | "select" | "small" | "source" | "span" | "stop" | "strike" | "strong" | "style" | "sub" | "sup" | "svg" | "switch" | "table" | "tbody" | "td" | "template" | "text" | "textpath" | "textarea" | "tfoot" | "th" | "thead" | "title" | "tr" | "track" | "tspan" | "tt" | "u" | "ul" | "use" | "var" | "video" | "view" | "wbr" | "x-ms-webview" | "xmp">(tagname: K): ElementListTagNameMap[K]; (tagname: string): NodeListOf<Element>; }
>"a" : "a"
element.href;