From ccf38f65671f5e59bb3c4093693767c11e2df3ae Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 21 May 2019 13:12:20 -0700 Subject: [PATCH 1/4] Add this-parameter workaround to Array.filter Allows anys.filter(Boolean) to once again return any[], not unknown[]. --- src/lib/es5.d.ts | 6 ++ .../booleanFilterAnyArray.errors.txt | 24 +++++++ .../reference/booleanFilterAnyArray.js | 24 +++++++ .../reference/booleanFilterAnyArray.symbols | 72 +++++++++++++++++++ .../reference/booleanFilterAnyArray.types | 49 +++++++++++++ ...tructuringParameterDeclaration4.errors.txt | 2 +- .../reference/promisePermutations.errors.txt | 2 +- .../reference/promisePermutations2.errors.txt | 2 +- .../reference/promisePermutations3.errors.txt | 4 +- .../reference/promiseTypeInference.errors.txt | 2 +- .../reference/redefineArray.errors.txt | 2 +- tests/cases/compiler/booleanFilterAnyArray.ts | 17 +++++ 12 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/booleanFilterAnyArray.errors.txt create mode 100644 tests/baselines/reference/booleanFilterAnyArray.js create mode 100644 tests/baselines/reference/booleanFilterAnyArray.symbols create mode 100644 tests/baselines/reference/booleanFilterAnyArray.types create mode 100644 tests/cases/compiler/booleanFilterAnyArray.ts diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index f2be6716c7299..12fce4fd227d5 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1133,6 +1133,12 @@ interface ReadonlyArray { * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: T, index: number, array: ReadonlyArray) => U, thisArg?: any): U[]; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(this: any[], callbackfn: (value: any, index: number, array: ReadonlyArray) => unknown, thisArg?: any): any[]; /** * Returns the elements of an array that meet the condition specified in a callback function. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. diff --git a/tests/baselines/reference/booleanFilterAnyArray.errors.txt b/tests/baselines/reference/booleanFilterAnyArray.errors.txt new file mode 100644 index 0000000000000..04e985a8ec762 --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/booleanFilterAnyArray.ts(14,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'xs' must be of type 'Ari', but here has type 'Ari'. + + +==== tests/cases/compiler/booleanFilterAnyArray.ts (1 errors) ==== + interface Bullean { } + interface BulleanConstructor { + new(v1?: any): Bullean; + (v2?: T): v2 is T; + } + + interface Ari { + filter(cb1: (value: T) => value is S): Ari; + filter(cb2: (value: T) => unknown): Ari; + } + declare var Bullean: BulleanConstructor; + declare let anys: Ari; + var xs: Ari; + var xs = anys.filter(Bullean) + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'xs' must be of type 'Ari', but here has type 'Ari'. + + declare let realanys: any[]; + var ys = realanys.filter(Boolean) + \ No newline at end of file diff --git a/tests/baselines/reference/booleanFilterAnyArray.js b/tests/baselines/reference/booleanFilterAnyArray.js new file mode 100644 index 0000000000000..bb81cba4da5d1 --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.js @@ -0,0 +1,24 @@ +//// [booleanFilterAnyArray.ts] +interface Bullean { } +interface BulleanConstructor { + new(v1?: any): Bullean; + (v2?: T): v2 is T; +} + +interface Ari { + filter(cb1: (value: T) => value is S): Ari; + filter(cb2: (value: T) => unknown): Ari; +} +declare var Bullean: BulleanConstructor; +declare let anys: Ari; +var xs: Ari; +var xs = anys.filter(Bullean) + +declare let realanys: any[]; +var ys = realanys.filter(Boolean) + + +//// [booleanFilterAnyArray.js] +var xs; +var xs = anys.filter(Bullean); +var ys = realanys.filter(Boolean); diff --git a/tests/baselines/reference/booleanFilterAnyArray.symbols b/tests/baselines/reference/booleanFilterAnyArray.symbols new file mode 100644 index 0000000000000..38fef9302aab6 --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.symbols @@ -0,0 +1,72 @@ +=== tests/cases/compiler/booleanFilterAnyArray.ts === +interface Bullean { } +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) + +interface BulleanConstructor { +>BulleanConstructor : Symbol(BulleanConstructor, Decl(booleanFilterAnyArray.ts, 0, 21)) + + new(v1?: any): Bullean; +>v1 : Symbol(v1, Decl(booleanFilterAnyArray.ts, 2, 8)) +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) + + (v2?: T): v2 is T; +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 3, 5)) +>v2 : Symbol(v2, Decl(booleanFilterAnyArray.ts, 3, 8)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 3, 5)) +>v2 : Symbol(v2, Decl(booleanFilterAnyArray.ts, 3, 8)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 3, 5)) +} + +interface Ari { +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) + + filter(cb1: (value: T) => value is S): Ari; +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>cb1 : Symbol(cb1, Decl(booleanFilterAnyArray.ts, 7, 24)) +>value : Symbol(value, Decl(booleanFilterAnyArray.ts, 7, 30)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>value : Symbol(value, Decl(booleanFilterAnyArray.ts, 7, 30)) +>S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) + + filter(cb2: (value: T) => unknown): Ari; +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>cb2 : Symbol(cb2, Decl(booleanFilterAnyArray.ts, 8, 11)) +>value : Symbol(value, Decl(booleanFilterAnyArray.ts, 8, 17)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +} +declare var Bullean: BulleanConstructor; +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) +>BulleanConstructor : Symbol(BulleanConstructor, Decl(booleanFilterAnyArray.ts, 0, 21)) + +declare let anys: Ari; +>anys : Symbol(anys, Decl(booleanFilterAnyArray.ts, 11, 11)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) + +var xs: Ari; +>xs : Symbol(xs, Decl(booleanFilterAnyArray.ts, 12, 3), Decl(booleanFilterAnyArray.ts, 13, 3)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) + +var xs = anys.filter(Bullean) +>xs : Symbol(xs, Decl(booleanFilterAnyArray.ts, 12, 3), Decl(booleanFilterAnyArray.ts, 13, 3)) +>anys.filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>anys : Symbol(anys, Decl(booleanFilterAnyArray.ts, 11, 11)) +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) + +declare let realanys: any[]; +>realanys : Symbol(realanys, Decl(booleanFilterAnyArray.ts, 15, 11)) + +var ys = realanys.filter(Boolean) +>ys : Symbol(ys, Decl(booleanFilterAnyArray.ts, 16, 3)) +>realanys.filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>realanys : Symbol(realanys, Decl(booleanFilterAnyArray.ts, 15, 11)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/booleanFilterAnyArray.types b/tests/baselines/reference/booleanFilterAnyArray.types new file mode 100644 index 0000000000000..21862ae71169e --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/booleanFilterAnyArray.ts === +interface Bullean { } +interface BulleanConstructor { + new(v1?: any): Bullean; +>v1 : any + + (v2?: T): v2 is T; +>v2 : T +} + +interface Ari { + filter(cb1: (value: T) => value is S): Ari; +>filter : { (cb1: (value: T) => value is S): Ari; (cb2: (value: T) => unknown): Ari; } +>cb1 : (value: T) => value is S +>value : T + + filter(cb2: (value: T) => unknown): Ari; +>filter : { (cb1: (value: T) => value is S): Ari; (cb2: (value: T) => unknown): Ari; } +>cb2 : (value: T) => unknown +>value : T +} +declare var Bullean: BulleanConstructor; +>Bullean : BulleanConstructor + +declare let anys: Ari; +>anys : Ari + +var xs: Ari; +>xs : Ari + +var xs = anys.filter(Bullean) +>xs : Ari +>anys.filter(Bullean) : Ari +>anys.filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } +>anys : Ari +>filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } +>Bullean : BulleanConstructor + +declare let realanys: any[]; +>realanys : any[] + +var ys = realanys.filter(Boolean) +>ys : unknown[] +>realanys.filter(Boolean) : unknown[] +>realanys.filter : { (callbackfn: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; } +>realanys : any[] +>filter : { (callbackfn: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; } +>Boolean : BooleanConstructor + diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index 7cd59c5a93aff..bfc763630909c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'? -!!! related TS2728 /.ts/lib.es5.d.ts:1368:13: 'Array' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1374:13: 'Array' is declared here. a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] ~~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type '[[any]]'. diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index c719d8a9b951e..c16db1eddcfeb 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -295,7 +295,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index b88ef28ca5c51..0ee6f4d8b8d00 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -294,7 +294,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 83a161af960d4..0f0a28c653f3f 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -303,7 +303,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -340,5 +340,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file diff --git a/tests/baselines/reference/promiseTypeInference.errors.txt b/tests/baselines/reference/promiseTypeInference.errors.txt index 1996f37e5402c..a2021d2f273c7 100644 --- a/tests/baselines/reference/promiseTypeInference.errors.txt +++ b/tests/baselines/reference/promiseTypeInference.errors.txt @@ -26,5 +26,5 @@ tests/cases/compiler/promiseTypeInference.ts(10,39): error TS2322: Type 'IPromis !!! error TS2322: Types of parameters 'success' and 'onfulfilled' are incompatible. !!! error TS2322: Type 'TResult1 | PromiseLike' is not assignable to type 'IPromise'. !!! error TS2322: Type 'TResult1' is not assignable to type 'IPromise'. -!!! related TS6502 /.ts/lib.es5.d.ts:1406:57: The expected type comes from the return type of this signature. +!!! related TS6502 /.ts/lib.es5.d.ts:1412:57: The expected type comes from the return type of this signature. \ No newline at end of file diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index c632915e72fd9..32adbcd066780 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -5,4 +5,4 @@ tests/cases/compiler/redefineArray.ts(1,1): error TS2741: Property 'isArray' is Array = function (n:number, s:string) {return n;}; ~~~~~ !!! error TS2741: Property 'isArray' is missing in type '(n: number, s: string) => number' but required in type 'ArrayConstructor'. -!!! related TS2728 /.ts/lib.es5.d.ts:1364:5: 'isArray' is declared here. \ No newline at end of file +!!! related TS2728 /.ts/lib.es5.d.ts:1370:5: 'isArray' is declared here. \ No newline at end of file diff --git a/tests/cases/compiler/booleanFilterAnyArray.ts b/tests/cases/compiler/booleanFilterAnyArray.ts new file mode 100644 index 0000000000000..54611a1d7f999 --- /dev/null +++ b/tests/cases/compiler/booleanFilterAnyArray.ts @@ -0,0 +1,17 @@ +interface Bullean { } +interface BulleanConstructor { + new(v1?: any): Bullean; + (v2?: T): v2 is T; +} + +interface Ari { + filter(cb1: (value: T) => value is S): Ari; + filter(cb2: (value: T) => unknown): Ari; +} +declare var Bullean: BulleanConstructor; +declare let anys: Ari; +var xs: Ari; +var xs = anys.filter(Bullean) + +declare let realanys: any[]; +var ys = realanys.filter(Boolean) From e1181888f66f37b8c6a0c79546e6f2fa6f551ade Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 21 May 2019 16:09:47 -0700 Subject: [PATCH 2/4] Add any constraint to Boolean factory function I want to test how well this works. --- src/lib/es5.d.ts | 4 +- .../booleanFilterAnyArray.errors.txt | 24 -------- .../reference/booleanFilterAnyArray.js | 15 ++++- .../reference/booleanFilterAnyArray.symbols | 48 +++++++++++++-- .../reference/booleanFilterAnyArray.types | 61 ++++++++++++++++--- tests/cases/compiler/booleanFilterAnyArray.ts | 9 ++- 6 files changed, 119 insertions(+), 42 deletions(-) delete mode 100644 tests/baselines/reference/booleanFilterAnyArray.errors.txt diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 12fce4fd227d5..e008680a77112 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -513,7 +513,7 @@ interface Boolean { interface BooleanConstructor { new(value?: any): Boolean; - (value?: T): value is Exclude; + (value?: T): value is Exclude; readonly prototype: Boolean; } @@ -1138,7 +1138,7 @@ interface ReadonlyArray { * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ - filter(this: any[], callbackfn: (value: any, index: number, array: ReadonlyArray) => unknown, thisArg?: any): any[]; + filter(this: ReadonlyArray, callbackfn: (value: any, index: number, array: ReadonlyArray) => unknown, thisArg?: any): any[]; /** * Returns the elements of an array that meet the condition specified in a callback function. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. diff --git a/tests/baselines/reference/booleanFilterAnyArray.errors.txt b/tests/baselines/reference/booleanFilterAnyArray.errors.txt deleted file mode 100644 index 04e985a8ec762..0000000000000 --- a/tests/baselines/reference/booleanFilterAnyArray.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/booleanFilterAnyArray.ts(14,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'xs' must be of type 'Ari', but here has type 'Ari'. - - -==== tests/cases/compiler/booleanFilterAnyArray.ts (1 errors) ==== - interface Bullean { } - interface BulleanConstructor { - new(v1?: any): Bullean; - (v2?: T): v2 is T; - } - - interface Ari { - filter(cb1: (value: T) => value is S): Ari; - filter(cb2: (value: T) => unknown): Ari; - } - declare var Bullean: BulleanConstructor; - declare let anys: Ari; - var xs: Ari; - var xs = anys.filter(Bullean) - ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'xs' must be of type 'Ari', but here has type 'Ari'. - - declare let realanys: any[]; - var ys = realanys.filter(Boolean) - \ No newline at end of file diff --git a/tests/baselines/reference/booleanFilterAnyArray.js b/tests/baselines/reference/booleanFilterAnyArray.js index bb81cba4da5d1..2cd319ca440ad 100644 --- a/tests/baselines/reference/booleanFilterAnyArray.js +++ b/tests/baselines/reference/booleanFilterAnyArray.js @@ -6,7 +6,7 @@ interface BulleanConstructor { } interface Ari { - filter(cb1: (value: T) => value is S): Ari; + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; filter(cb2: (value: T) => unknown): Ari; } declare var Bullean: BulleanConstructor; @@ -15,10 +15,23 @@ var xs: Ari; var xs = anys.filter(Bullean) declare let realanys: any[]; +var ys: any[]; var ys = realanys.filter(Boolean) + +var foo = [{ name: 'x' }] +var foor: Array<{name: string}> +var foor = foo.filter(x => x.name) +var foos: Array +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) //// [booleanFilterAnyArray.js] var xs; var xs = anys.filter(Bullean); +var ys; var ys = realanys.filter(Boolean); +var foo = [{ name: 'x' }]; +var foor; +var foor = foo.filter(function (x) { return x.name; }); +var foos; +var foos = [true, true, false, null].filter(function (thing) { return thing !== null; }); diff --git a/tests/baselines/reference/booleanFilterAnyArray.symbols b/tests/baselines/reference/booleanFilterAnyArray.symbols index 38fef9302aab6..1e0207fdf8049 100644 --- a/tests/baselines/reference/booleanFilterAnyArray.symbols +++ b/tests/baselines/reference/booleanFilterAnyArray.symbols @@ -21,8 +21,8 @@ interface Ari { >Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) >T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) - filter(cb1: (value: T) => value is S): Ari; ->filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) >S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) >T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) >cb1 : Symbol(cb1, Decl(booleanFilterAnyArray.ts, 7, 24)) @@ -30,11 +30,13 @@ interface Ari { >T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) >value : Symbol(value, Decl(booleanFilterAnyArray.ts, 7, 30)) >S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) >Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) >S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) filter(cb2: (value: T) => unknown): Ari; ->filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) >cb2 : Symbol(cb2, Decl(booleanFilterAnyArray.ts, 8, 11)) >value : Symbol(value, Decl(booleanFilterAnyArray.ts, 8, 17)) >T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) @@ -55,18 +57,52 @@ var xs: Ari; var xs = anys.filter(Bullean) >xs : Symbol(xs, Decl(booleanFilterAnyArray.ts, 12, 3), Decl(booleanFilterAnyArray.ts, 13, 3)) ->anys.filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>anys.filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) >anys : Symbol(anys, Decl(booleanFilterAnyArray.ts, 11, 11)) ->filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 63)) +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) >Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) declare let realanys: any[]; >realanys : Symbol(realanys, Decl(booleanFilterAnyArray.ts, 15, 11)) +var ys: any[]; +>ys : Symbol(ys, Decl(booleanFilterAnyArray.ts, 16, 3), Decl(booleanFilterAnyArray.ts, 17, 3)) + var ys = realanys.filter(Boolean) ->ys : Symbol(ys, Decl(booleanFilterAnyArray.ts, 16, 3)) +>ys : Symbol(ys, Decl(booleanFilterAnyArray.ts, 16, 3), Decl(booleanFilterAnyArray.ts, 17, 3)) >realanys.filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >realanys : Symbol(realanys, Decl(booleanFilterAnyArray.ts, 15, 11)) >filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +var foo = [{ name: 'x' }] +>foo : Symbol(foo, Decl(booleanFilterAnyArray.ts, 19, 3)) +>name : Symbol(name, Decl(booleanFilterAnyArray.ts, 19, 12)) + +var foor: Array<{name: string}> +>foor : Symbol(foor, Decl(booleanFilterAnyArray.ts, 20, 3), Decl(booleanFilterAnyArray.ts, 21, 3)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>name : Symbol(name, Decl(booleanFilterAnyArray.ts, 20, 17)) + +var foor = foo.filter(x => x.name) +>foor : Symbol(foor, Decl(booleanFilterAnyArray.ts, 20, 3), Decl(booleanFilterAnyArray.ts, 21, 3)) +>foo.filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(booleanFilterAnyArray.ts, 19, 3)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(booleanFilterAnyArray.ts, 21, 22)) +>x.name : Symbol(name, Decl(booleanFilterAnyArray.ts, 19, 12)) +>x : Symbol(x, Decl(booleanFilterAnyArray.ts, 21, 22)) +>name : Symbol(name, Decl(booleanFilterAnyArray.ts, 19, 12)) + +var foos: Array +>foos : Symbol(foos, Decl(booleanFilterAnyArray.ts, 22, 3), Decl(booleanFilterAnyArray.ts, 23, 3)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) +>foos : Symbol(foos, Decl(booleanFilterAnyArray.ts, 22, 3), Decl(booleanFilterAnyArray.ts, 23, 3)) +>[true, true, false, null].filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>thing : Symbol(thing, Decl(booleanFilterAnyArray.ts, 23, 45)) +>thing : Symbol(thing, Decl(booleanFilterAnyArray.ts, 23, 45)) +>thing : Symbol(thing, Decl(booleanFilterAnyArray.ts, 23, 45)) + diff --git a/tests/baselines/reference/booleanFilterAnyArray.types b/tests/baselines/reference/booleanFilterAnyArray.types index 21862ae71169e..a1d4303ef8e30 100644 --- a/tests/baselines/reference/booleanFilterAnyArray.types +++ b/tests/baselines/reference/booleanFilterAnyArray.types @@ -9,13 +9,13 @@ interface BulleanConstructor { } interface Ari { - filter(cb1: (value: T) => value is S): Ari; ->filter : { (cb1: (value: T) => value is S): Ari; (cb2: (value: T) => unknown): Ari; } + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; +>filter : { (cb1: (value: T) => value is S): T extends any ? Ari : Ari; (cb2: (value: T) => unknown): Ari; } >cb1 : (value: T) => value is S >value : T filter(cb2: (value: T) => unknown): Ari; ->filter : { (cb1: (value: T) => value is S): Ari; (cb2: (value: T) => unknown): Ari; } +>filter : { (cb1: (value: T) => value is S): T extends any ? Ari : Ari; (cb2: (value: T) => unknown): Ari; } >cb2 : (value: T) => unknown >value : T } @@ -30,20 +30,65 @@ var xs: Ari; var xs = anys.filter(Bullean) >xs : Ari ->anys.filter(Bullean) : Ari ->anys.filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } +>anys.filter(Bullean) : Ari +>anys.filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } >anys : Ari ->filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } +>filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } >Bullean : BulleanConstructor declare let realanys: any[]; >realanys : any[] +var ys: any[]; +>ys : any[] + var ys = realanys.filter(Boolean) ->ys : unknown[] ->realanys.filter(Boolean) : unknown[] +>ys : any[] +>realanys.filter(Boolean) : any[] >realanys.filter : { (callbackfn: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; } >realanys : any[] >filter : { (callbackfn: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; } >Boolean : BooleanConstructor +var foo = [{ name: 'x' }] +>foo : { name: string; }[] +>[{ name: 'x' }] : { name: string; }[] +>{ name: 'x' } : { name: string; } +>name : string +>'x' : "x" + +var foor: Array<{name: string}> +>foor : { name: string; }[] +>name : string + +var foor = foo.filter(x => x.name) +>foor : { name: string; }[] +>foo.filter(x => x.name) : { name: string; }[] +>foo.filter : { (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; } +>foo : { name: string; }[] +>filter : { (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; } +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + +var foos: Array +>foos : boolean[] + +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) +>foos : boolean[] +>[true, true, false, null].filter((thing): thing is boolean => thing !== null) : boolean[] +>[true, true, false, null].filter : { (callbackfn: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; } +>[true, true, false, null] : boolean[] +>true : true +>true : true +>false : false +>null : null +>filter : { (callbackfn: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; } +>(thing): thing is boolean => thing !== null : (thing: boolean) => thing is boolean +>thing : boolean +>thing !== null : boolean +>thing : boolean +>null : null + diff --git a/tests/cases/compiler/booleanFilterAnyArray.ts b/tests/cases/compiler/booleanFilterAnyArray.ts index 54611a1d7f999..db5f38e78f9a0 100644 --- a/tests/cases/compiler/booleanFilterAnyArray.ts +++ b/tests/cases/compiler/booleanFilterAnyArray.ts @@ -5,7 +5,7 @@ interface BulleanConstructor { } interface Ari { - filter(cb1: (value: T) => value is S): Ari; + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; filter(cb2: (value: T) => unknown): Ari; } declare var Bullean: BulleanConstructor; @@ -14,4 +14,11 @@ var xs: Ari; var xs = anys.filter(Bullean) declare let realanys: any[]; +var ys: any[]; var ys = realanys.filter(Boolean) + +var foo = [{ name: 'x' }] +var foor: Array<{name: string}> +var foor = foo.filter(x => x.name) +var foos: Array +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) From cff71c9369e33203bcd72ad628bab2e129b1a229 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 22 May 2019 08:43:24 -0700 Subject: [PATCH 3/4] Remove Boolean factory type guard --- src/lib/es5.d.ts | 8 +---- ...tructuringParameterDeclaration4.errors.txt | 2 +- .../reference/promisePermutations.errors.txt | 2 +- .../reference/promisePermutations2.errors.txt | 2 +- .../reference/promisePermutations3.errors.txt | 4 +-- .../reference/promiseTypeInference.errors.txt | 2 +- .../reference/redefineArray.errors.txt | 2 +- .../reference/typeGuardBoolean.errors.txt | 32 +++++++++++++++++++ .../reference/typeGuardBoolean.types | 12 +++---- 9 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/typeGuardBoolean.errors.txt diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index e008680a77112..0d1481dd7d26b 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -513,7 +513,7 @@ interface Boolean { interface BooleanConstructor { new(value?: any): Boolean; - (value?: T): value is Exclude; + (value?: T): boolean; readonly prototype: Boolean; } @@ -1133,12 +1133,6 @@ interface ReadonlyArray { * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: T, index: number, array: ReadonlyArray) => U, thisArg?: any): U[]; - /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. - */ - filter(this: ReadonlyArray, callbackfn: (value: any, index: number, array: ReadonlyArray) => unknown, thisArg?: any): any[]; /** * Returns the elements of an array that meet the condition specified in a callback function. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index bfc763630909c..7cd59c5a93aff 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'? -!!! related TS2728 /.ts/lib.es5.d.ts:1374:13: 'Array' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1368:13: 'Array' is declared here. a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] ~~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type '[[any]]'. diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index c16db1eddcfeb..c719d8a9b951e 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -295,7 +295,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 0ee6f4d8b8d00..b88ef28ca5c51 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -294,7 +294,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 0f0a28c653f3f..83a161af960d4 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -303,7 +303,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -340,5 +340,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file diff --git a/tests/baselines/reference/promiseTypeInference.errors.txt b/tests/baselines/reference/promiseTypeInference.errors.txt index a2021d2f273c7..1996f37e5402c 100644 --- a/tests/baselines/reference/promiseTypeInference.errors.txt +++ b/tests/baselines/reference/promiseTypeInference.errors.txt @@ -26,5 +26,5 @@ tests/cases/compiler/promiseTypeInference.ts(10,39): error TS2322: Type 'IPromis !!! error TS2322: Types of parameters 'success' and 'onfulfilled' are incompatible. !!! error TS2322: Type 'TResult1 | PromiseLike' is not assignable to type 'IPromise'. !!! error TS2322: Type 'TResult1' is not assignable to type 'IPromise'. -!!! related TS6502 /.ts/lib.es5.d.ts:1412:57: The expected type comes from the return type of this signature. +!!! related TS6502 /.ts/lib.es5.d.ts:1406:57: The expected type comes from the return type of this signature. \ No newline at end of file diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 32adbcd066780..c632915e72fd9 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -5,4 +5,4 @@ tests/cases/compiler/redefineArray.ts(1,1): error TS2741: Property 'isArray' is Array = function (n:number, s:string) {return n;}; ~~~~~ !!! error TS2741: Property 'isArray' is missing in type '(n: number, s: string) => number' but required in type 'ArrayConstructor'. -!!! related TS2728 /.ts/lib.es5.d.ts:1370:5: 'isArray' is declared here. \ No newline at end of file +!!! related TS2728 /.ts/lib.es5.d.ts:1364:5: 'isArray' is declared here. \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardBoolean.errors.txt b/tests/baselines/reference/typeGuardBoolean.errors.txt new file mode 100644 index 0000000000000..b0d14256ccc3a --- /dev/null +++ b/tests/baselines/reference/typeGuardBoolean.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(5,7): error TS2322: Type 'string | null' is not assignable to type 'null'. + Type 'string' is not assignable to type 'null'. +tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(8,7): error TS2322: Type 'string | null' is not assignable to type 'string'. + Type 'null' is not assignable to type 'string'. +tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(11,7): error TS2322: Type 'string | undefined' is not assignable to type 'string'. + Type 'undefined' is not assignable to type 'string'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts (3 errors) ==== + function test(strOrNull: string | null, strOrUndefined: string | undefined) { + var str: string = "original"; + var nil: null; + if (!Boolean(strOrNull)) { + nil = strOrNull; + ~~~ +!!! error TS2322: Type 'string | null' is not assignable to type 'null'. +!!! error TS2322: Type 'string' is not assignable to type 'null'. + } + else { + str = strOrNull; + ~~~ +!!! error TS2322: Type 'string | null' is not assignable to type 'string'. +!!! error TS2322: Type 'null' is not assignable to type 'string'. + } + if (Boolean(strOrUndefined)) { + str = strOrUndefined; + ~~~ +!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'. +!!! error TS2322: Type 'undefined' is not assignable to type 'string'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardBoolean.types b/tests/baselines/reference/typeGuardBoolean.types index db3d6f39cd841..9707eb2efb397 100644 --- a/tests/baselines/reference/typeGuardBoolean.types +++ b/tests/baselines/reference/typeGuardBoolean.types @@ -20,15 +20,15 @@ function test(strOrNull: string | null, strOrUndefined: string | undefined) { >strOrNull : string | null nil = strOrNull; ->nil = strOrNull : null +>nil = strOrNull : string | null >nil : null ->strOrNull : null +>strOrNull : string | null } else { str = strOrNull; ->str = strOrNull : string +>str = strOrNull : string | null >str : string ->strOrNull : string +>strOrNull : string | null } if (Boolean(strOrUndefined)) { >Boolean(strOrUndefined) : boolean @@ -36,9 +36,9 @@ function test(strOrNull: string | null, strOrUndefined: string | undefined) { >strOrUndefined : string | undefined str = strOrUndefined; ->str = strOrUndefined : string +>str = strOrUndefined : string | undefined >str : string ->strOrUndefined : string +>strOrUndefined : string | undefined } } From ab9d935662a5880ee825c9bfe458a363d965071e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 22 May 2019 08:44:17 -0700 Subject: [PATCH 4/4] Remove typeGuardBoolean test --- .../reference/typeGuardBoolean.errors.txt | 32 -------------- tests/baselines/reference/typeGuardBoolean.js | 30 ------------- .../reference/typeGuardBoolean.symbols | 35 --------------- .../reference/typeGuardBoolean.types | 44 ------------------- .../typeGuards/typeGuardBoolean.ts | 14 ------ 5 files changed, 155 deletions(-) delete mode 100644 tests/baselines/reference/typeGuardBoolean.errors.txt delete mode 100644 tests/baselines/reference/typeGuardBoolean.js delete mode 100644 tests/baselines/reference/typeGuardBoolean.symbols delete mode 100644 tests/baselines/reference/typeGuardBoolean.types delete mode 100644 tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts diff --git a/tests/baselines/reference/typeGuardBoolean.errors.txt b/tests/baselines/reference/typeGuardBoolean.errors.txt deleted file mode 100644 index b0d14256ccc3a..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.errors.txt +++ /dev/null @@ -1,32 +0,0 @@ -tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(5,7): error TS2322: Type 'string | null' is not assignable to type 'null'. - Type 'string' is not assignable to type 'null'. -tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(8,7): error TS2322: Type 'string | null' is not assignable to type 'string'. - Type 'null' is not assignable to type 'string'. -tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(11,7): error TS2322: Type 'string | undefined' is not assignable to type 'string'. - Type 'undefined' is not assignable to type 'string'. - - -==== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts (3 errors) ==== - function test(strOrNull: string | null, strOrUndefined: string | undefined) { - var str: string = "original"; - var nil: null; - if (!Boolean(strOrNull)) { - nil = strOrNull; - ~~~ -!!! error TS2322: Type 'string | null' is not assignable to type 'null'. -!!! error TS2322: Type 'string' is not assignable to type 'null'. - } - else { - str = strOrNull; - ~~~ -!!! error TS2322: Type 'string | null' is not assignable to type 'string'. -!!! error TS2322: Type 'null' is not assignable to type 'string'. - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - ~~~ -!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'. -!!! error TS2322: Type 'undefined' is not assignable to type 'string'. - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardBoolean.js b/tests/baselines/reference/typeGuardBoolean.js deleted file mode 100644 index 1bfe41983d83b..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [typeGuardBoolean.ts] -function test(strOrNull: string | null, strOrUndefined: string | undefined) { - var str: string = "original"; - var nil: null; - if (!Boolean(strOrNull)) { - nil = strOrNull; - } - else { - str = strOrNull; - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - } -} - - -//// [typeGuardBoolean.js] -function test(strOrNull, strOrUndefined) { - var str = "original"; - var nil; - if (!Boolean(strOrNull)) { - nil = strOrNull; - } - else { - str = strOrNull; - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - } -} diff --git a/tests/baselines/reference/typeGuardBoolean.symbols b/tests/baselines/reference/typeGuardBoolean.symbols deleted file mode 100644 index 6a08dcbda8a06..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.symbols +++ /dev/null @@ -1,35 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts === -function test(strOrNull: string | null, strOrUndefined: string | undefined) { ->test : Symbol(test, Decl(typeGuardBoolean.ts, 0, 0)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) ->strOrUndefined : Symbol(strOrUndefined, Decl(typeGuardBoolean.ts, 0, 39)) - - var str: string = "original"; ->str : Symbol(str, Decl(typeGuardBoolean.ts, 1, 5)) - - var nil: null; ->nil : Symbol(nil, Decl(typeGuardBoolean.ts, 2, 5)) - - if (!Boolean(strOrNull)) { ->Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) - - nil = strOrNull; ->nil : Symbol(nil, Decl(typeGuardBoolean.ts, 2, 5)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) - } - else { - str = strOrNull; ->str : Symbol(str, Decl(typeGuardBoolean.ts, 1, 5)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) - } - if (Boolean(strOrUndefined)) { ->Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->strOrUndefined : Symbol(strOrUndefined, Decl(typeGuardBoolean.ts, 0, 39)) - - str = strOrUndefined; ->str : Symbol(str, Decl(typeGuardBoolean.ts, 1, 5)) ->strOrUndefined : Symbol(strOrUndefined, Decl(typeGuardBoolean.ts, 0, 39)) - } -} - diff --git a/tests/baselines/reference/typeGuardBoolean.types b/tests/baselines/reference/typeGuardBoolean.types deleted file mode 100644 index 9707eb2efb397..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.types +++ /dev/null @@ -1,44 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts === -function test(strOrNull: string | null, strOrUndefined: string | undefined) { ->test : (strOrNull: string | null, strOrUndefined: string | undefined) => void ->strOrNull : string | null ->null : null ->strOrUndefined : string | undefined - - var str: string = "original"; ->str : string ->"original" : "original" - - var nil: null; ->nil : null ->null : null - - if (!Boolean(strOrNull)) { ->!Boolean(strOrNull) : boolean ->Boolean(strOrNull) : boolean ->Boolean : BooleanConstructor ->strOrNull : string | null - - nil = strOrNull; ->nil = strOrNull : string | null ->nil : null ->strOrNull : string | null - } - else { - str = strOrNull; ->str = strOrNull : string | null ->str : string ->strOrNull : string | null - } - if (Boolean(strOrUndefined)) { ->Boolean(strOrUndefined) : boolean ->Boolean : BooleanConstructor ->strOrUndefined : string | undefined - - str = strOrUndefined; ->str = strOrUndefined : string | undefined ->str : string ->strOrUndefined : string | undefined - } -} - diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts deleted file mode 100644 index 3f2dde227ba8c..0000000000000 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @strictNullChecks: true -function test(strOrNull: string | null, strOrUndefined: string | undefined) { - var str: string = "original"; - var nil: null; - if (!Boolean(strOrNull)) { - nil = strOrNull; - } - else { - str = strOrNull; - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - } -}