From 06928b669e69495333ef51ed3e02332898cdd1b7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 21 Apr 2016 10:50:08 -0700 Subject: [PATCH] Accepting new baselines --- .../controlFlowBinaryOrExpression.js | 37 +++++++++ .../controlFlowBinaryOrExpression.symbols | 69 +++++++++++++++++ .../controlFlowBinaryOrExpression.types | 75 +++++++++++++++++++ .../reference/instanceOfAssignability.types | 4 +- .../stringLiteralTypesAsTags01.types | 8 +- .../stringLiteralTypesAsTags02.types | 8 +- .../stringLiteralTypesAsTags03.types | 8 +- .../typeGuardsWithInstanceOf.errors.txt | 14 ++++ .../typeGuardsWithInstanceOf.symbols | 26 ------- .../reference/typeGuardsWithInstanceOf.types | 31 -------- 10 files changed, 209 insertions(+), 71 deletions(-) create mode 100644 tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt delete mode 100644 tests/baselines/reference/typeGuardsWithInstanceOf.symbols delete mode 100644 tests/baselines/reference/typeGuardsWithInstanceOf.types diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.js b/tests/baselines/reference/controlFlowBinaryOrExpression.js index 350e383a1f..fb48c5a23e 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.js +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.js @@ -8,9 +8,36 @@ x; // string | number x = ""; cond || (x = 0); x; // string | number + +export interface NodeList { + length: number; +} + +export interface HTMLCollection { + length: number; +} + +declare function isNodeList(sourceObj: any): sourceObj is NodeList; +declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection; + +type EventTargetLike = {a: string} | HTMLCollection | NodeList; + +var sourceObj: EventTargetLike = undefined; +if (isNodeList(sourceObj)) { + sourceObj.length; +} + +if (isHTMLCollection(sourceObj)) { + sourceObj.length; +} + +if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { + sourceObj.length; +} //// [controlFlowBinaryOrExpression.js] +"use strict"; var x; var cond; (x = "") || (x = 0); @@ -18,3 +45,13 @@ x; // string | number x = ""; cond || (x = 0); x; // string | number +var sourceObj = undefined; +if (isNodeList(sourceObj)) { + sourceObj.length; +} +if (isHTMLCollection(sourceObj)) { + sourceObj.length; +} +if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { + sourceObj.length; +} diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.symbols b/tests/baselines/reference/controlFlowBinaryOrExpression.symbols index 286612ef4d..e47bdb19d3 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.symbols +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.symbols @@ -22,3 +22,72 @@ cond || (x = 0); x; // string | number >x : Symbol(x, Decl(controlFlowBinaryOrExpression.ts, 0, 3)) +export interface NodeList { +>NodeList : Symbol(NodeList, Decl(controlFlowBinaryOrExpression.ts, 8, 2)) + + length: number; +>length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +} + +export interface HTMLCollection { +>HTMLCollection : Symbol(HTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 12, 1)) + + length: number; +>length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +} + +declare function isNodeList(sourceObj: any): sourceObj is NodeList; +>isNodeList : Symbol(isNodeList, Decl(controlFlowBinaryOrExpression.ts, 16, 1)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 18, 28)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 18, 28)) +>NodeList : Symbol(NodeList, Decl(controlFlowBinaryOrExpression.ts, 8, 2)) + +declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection; +>isHTMLCollection : Symbol(isHTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 18, 67)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 19, 34)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 19, 34)) +>HTMLCollection : Symbol(HTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 12, 1)) + +type EventTargetLike = {a: string} | HTMLCollection | NodeList; +>EventTargetLike : Symbol(EventTargetLike, Decl(controlFlowBinaryOrExpression.ts, 19, 79)) +>a : Symbol(a, Decl(controlFlowBinaryOrExpression.ts, 21, 24)) +>HTMLCollection : Symbol(HTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 12, 1)) +>NodeList : Symbol(NodeList, Decl(controlFlowBinaryOrExpression.ts, 8, 2)) + +var sourceObj: EventTargetLike = undefined; +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) +>EventTargetLike : Symbol(EventTargetLike, Decl(controlFlowBinaryOrExpression.ts, 19, 79)) +>undefined : Symbol(undefined) + +if (isNodeList(sourceObj)) { +>isNodeList : Symbol(isNodeList, Decl(controlFlowBinaryOrExpression.ts, 16, 1)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) + + sourceObj.length; +>sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) +>length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +} + +if (isHTMLCollection(sourceObj)) { +>isHTMLCollection : Symbol(isHTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 18, 67)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) + + sourceObj.length; +>sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) +>length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +} + +if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { +>isNodeList : Symbol(isNodeList, Decl(controlFlowBinaryOrExpression.ts, 16, 1)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) +>isHTMLCollection : Symbol(isHTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 18, 67)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) + + sourceObj.length; +>sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) +>length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +} + diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.types b/tests/baselines/reference/controlFlowBinaryOrExpression.types index 404e153788..8c1cd32d8d 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.types +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.types @@ -35,3 +35,78 @@ cond || (x = 0); x; // string | number >x : string | number +export interface NodeList { +>NodeList : NodeList + + length: number; +>length : number +} + +export interface HTMLCollection { +>HTMLCollection : HTMLCollection + + length: number; +>length : number +} + +declare function isNodeList(sourceObj: any): sourceObj is NodeList; +>isNodeList : (sourceObj: any) => sourceObj is NodeList +>sourceObj : any +>sourceObj : any +>NodeList : NodeList + +declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection; +>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection +>sourceObj : any +>sourceObj : any +>HTMLCollection : HTMLCollection + +type EventTargetLike = {a: string} | HTMLCollection | NodeList; +>EventTargetLike : { a: string; } | HTMLCollection | NodeList +>a : string +>HTMLCollection : HTMLCollection +>NodeList : NodeList + +var sourceObj: EventTargetLike = undefined; +>sourceObj : { a: string; } | HTMLCollection | NodeList +>EventTargetLike : { a: string; } | HTMLCollection | NodeList +>undefined : any +>undefined : undefined + +if (isNodeList(sourceObj)) { +>isNodeList(sourceObj) : boolean +>isNodeList : (sourceObj: any) => sourceObj is NodeList +>sourceObj : { a: string; } | HTMLCollection + + sourceObj.length; +>sourceObj.length : number +>sourceObj : HTMLCollection +>length : number +} + +if (isHTMLCollection(sourceObj)) { +>isHTMLCollection(sourceObj) : boolean +>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection +>sourceObj : HTMLCollection | { a: string; } + + sourceObj.length; +>sourceObj.length : number +>sourceObj : HTMLCollection +>length : number +} + +if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { +>isNodeList(sourceObj) || isHTMLCollection(sourceObj) : boolean +>isNodeList(sourceObj) : boolean +>isNodeList : (sourceObj: any) => sourceObj is NodeList +>sourceObj : HTMLCollection | { a: string; } +>isHTMLCollection(sourceObj) : boolean +>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection +>sourceObj : { a: string; } + + sourceObj.length; +>sourceObj.length : number +>sourceObj : HTMLCollection +>length : number +} + diff --git a/tests/baselines/reference/instanceOfAssignability.types b/tests/baselines/reference/instanceOfAssignability.types index 12b2d32606..5fa55aa6d8 100644 --- a/tests/baselines/reference/instanceOfAssignability.types +++ b/tests/baselines/reference/instanceOfAssignability.types @@ -133,8 +133,8 @@ function fn5(x: Derived1) { // 1.5: y: Derived1 // Want: ??? let y = x; ->y : Derived1 ->x : Derived1 +>y : {} +>x : {} } } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.types b/tests/baselines/reference/stringLiteralTypesAsTags01.types index a7f403e76e..30f60a5766 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.types @@ -99,8 +99,8 @@ if (hasKind(x, "A")) { } else { let b = x; ->b : A ->x : A +>b : {} +>x : {} } if (!hasKind(x, "B")) { @@ -116,6 +116,6 @@ if (!hasKind(x, "B")) { } else { let d = x; ->d : A ->x : A +>d : {} +>x : {} } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.types b/tests/baselines/reference/stringLiteralTypesAsTags02.types index edad220b08..58a2209786 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags02.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.types @@ -93,8 +93,8 @@ if (hasKind(x, "A")) { } else { let b = x; ->b : A ->x : A +>b : {} +>x : {} } if (!hasKind(x, "B")) { @@ -110,6 +110,6 @@ if (!hasKind(x, "B")) { } else { let d = x; ->d : A ->x : A +>d : {} +>x : {} } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.types b/tests/baselines/reference/stringLiteralTypesAsTags03.types index 2581665938..a7cef3ec20 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags03.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.types @@ -96,8 +96,8 @@ if (hasKind(x, "A")) { } else { let b = x; ->b : A ->x : A +>b : {} +>x : {} } if (!hasKind(x, "B")) { @@ -113,6 +113,6 @@ if (!hasKind(x, "B")) { } else { let d = x; ->d : A ->x : A +>d : {} +>x : {} } diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt new file mode 100644 index 0000000000..28cc85695b --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(7,20): error TS2339: Property 'global' does not exist on type '{}'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts (1 errors) ==== + interface I { global: string; } + var result: I; + var result2: I; + + if (!(result instanceof RegExp)) { + result = result2; + } else if (!result.global) { + ~~~~~~ +!!! error TS2339: Property 'global' does not exist on type '{}'. + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.symbols b/tests/baselines/reference/typeGuardsWithInstanceOf.symbols deleted file mode 100644 index cc2695e6ae..0000000000 --- a/tests/baselines/reference/typeGuardsWithInstanceOf.symbols +++ /dev/null @@ -1,26 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts === -interface I { global: string; } ->I : Symbol(I, Decl(typeGuardsWithInstanceOf.ts, 0, 0)) ->global : Symbol(I.global, Decl(typeGuardsWithInstanceOf.ts, 0, 13)) - -var result: I; ->result : Symbol(result, Decl(typeGuardsWithInstanceOf.ts, 1, 3)) ->I : Symbol(I, Decl(typeGuardsWithInstanceOf.ts, 0, 0)) - -var result2: I; ->result2 : Symbol(result2, Decl(typeGuardsWithInstanceOf.ts, 2, 3)) ->I : Symbol(I, Decl(typeGuardsWithInstanceOf.ts, 0, 0)) - -if (!(result instanceof RegExp)) { ->result : Symbol(result, Decl(typeGuardsWithInstanceOf.ts, 1, 3)) ->RegExp : Symbol(RegExp, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) - - result = result2; ->result : Symbol(result, Decl(typeGuardsWithInstanceOf.ts, 1, 3)) ->result2 : Symbol(result2, Decl(typeGuardsWithInstanceOf.ts, 2, 3)) - -} else if (!result.global) { ->result.global : Symbol(I.global, Decl(typeGuardsWithInstanceOf.ts, 0, 13)) ->result : Symbol(result, Decl(typeGuardsWithInstanceOf.ts, 1, 3)) ->global : Symbol(I.global, Decl(typeGuardsWithInstanceOf.ts, 0, 13)) -} diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.types b/tests/baselines/reference/typeGuardsWithInstanceOf.types deleted file mode 100644 index 0d7b477fae..0000000000 --- a/tests/baselines/reference/typeGuardsWithInstanceOf.types +++ /dev/null @@ -1,31 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts === -interface I { global: string; } ->I : I ->global : string - -var result: I; ->result : I ->I : I - -var result2: I; ->result2 : I ->I : I - -if (!(result instanceof RegExp)) { ->!(result instanceof RegExp) : boolean ->(result instanceof RegExp) : boolean ->result instanceof RegExp : boolean ->result : I ->RegExp : RegExpConstructor - - result = result2; ->result = result2 : I ->result : I ->result2 : I - -} else if (!result.global) { ->!result.global : boolean ->result.global : string ->result : I ->global : string -}