Skip to content

Commit cff71c9

Browse files
committed
Remove Boolean factory type guard
1 parent e118188 commit cff71c9

9 files changed

+46
-20
lines changed

src/lib/es5.d.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ interface Boolean {
513513

514514
interface BooleanConstructor {
515515
new(value?: any): Boolean;
516-
<T extends any>(value?: T): value is Exclude<T, false | null | undefined | '' | 0>;
516+
<T>(value?: T): boolean;
517517
readonly prototype: Boolean;
518518
}
519519

@@ -1133,12 +1133,6 @@ interface ReadonlyArray<T> {
11331133
* @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.
11341134
*/
11351135
map<U>(callbackfn: (value: T, index: number, array: ReadonlyArray<T>) => U, thisArg?: any): U[];
1136-
/**
1137-
* Returns the elements of an array that meet the condition specified in a callback function.
1138-
* @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.
1139-
* @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.
1140-
*/
1141-
filter(this: ReadonlyArray<never>, callbackfn: (value: any, index: number, array: ReadonlyArray<any>) => unknown, thisArg?: any): any[];
11421136
/**
11431137
* Returns the elements of an array that meet the condition specified in a callback function.
11441138
* @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.

tests/baselines/reference/destructuringParameterDeclaration4.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
4141
a1(...array2); // Error parameter type is (number|string)[]
4242
~~~~~~
4343
!!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
44-
!!! related TS2728 /.ts/lib.es5.d.ts:1374:13: 'Array' is declared here.
44+
!!! related TS2728 /.ts/lib.es5.d.ts:1368:13: 'Array' is declared here.
4545
a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
4646
~~~~~~~~
4747
!!! error TS2322: Type 'string' is not assignable to type '[[any]]'.

tests/baselines/reference/promisePermutations.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
295295
~~~~~~~~~
296296
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
297297
!!! error TS2345: Property 'catch' is missing in type 'IPromise<string>' but required in type 'Promise<number>'.
298-
!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here.
298+
!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here.
299299
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok
300300

301301
var r11: IPromise<number>;

tests/baselines/reference/promisePermutations2.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
294294
~~~~~~~~~
295295
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
296296
!!! error TS2345: Property 'catch' is missing in type 'IPromise<string>' but required in type 'Promise<number>'.
297-
!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here.
297+
!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here.
298298
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok
299299

300300
var r11: IPromise<number>;

tests/baselines/reference/promisePermutations3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
303303
~~~~~~~~~
304304
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
305305
!!! error TS2345: Property 'catch' is missing in type 'IPromise<string>' but required in type 'Promise<number>'.
306-
!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here.
306+
!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here.
307307
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok
308308

309309
var r11: IPromise<number>;
@@ -340,5 +340,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
340340
~~~~~~~~~~~~~~~
341341
!!! error TS2345: Argument of type '{ <T>(x: T): IPromise<T>; <T>(x: T, y: T): Promise<T>; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise<unknown>'.
342342
!!! error TS2345: Property 'catch' is missing in type 'IPromise<any>' but required in type 'Promise<unknown>'.
343-
!!! related TS2728 /.ts/lib.es5.d.ts:1419:5: 'catch' is declared here.
343+
!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here.
344344
var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok

tests/baselines/reference/promiseTypeInference.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ tests/cases/compiler/promiseTypeInference.ts(10,39): error TS2322: Type 'IPromis
2626
!!! error TS2322: Types of parameters 'success' and 'onfulfilled' are incompatible.
2727
!!! error TS2322: Type 'TResult1 | PromiseLike<TResult1>' is not assignable to type 'IPromise<TResult1 | TResult2>'.
2828
!!! error TS2322: Type 'TResult1' is not assignable to type 'IPromise<TResult1 | TResult2>'.
29-
!!! related TS6502 /.ts/lib.es5.d.ts:1412:57: The expected type comes from the return type of this signature.
29+
!!! related TS6502 /.ts/lib.es5.d.ts:1406:57: The expected type comes from the return type of this signature.
3030

tests/baselines/reference/redefineArray.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ tests/cases/compiler/redefineArray.ts(1,1): error TS2741: Property 'isArray' is
55
Array = function (n:number, s:string) {return n;};
66
~~~~~
77
!!! error TS2741: Property 'isArray' is missing in type '(n: number, s: string) => number' but required in type 'ArrayConstructor'.
8-
!!! related TS2728 /.ts/lib.es5.d.ts:1370:5: 'isArray' is declared here.
8+
!!! related TS2728 /.ts/lib.es5.d.ts:1364:5: 'isArray' is declared here.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(5,7): error TS2322: Type 'string | null' is not assignable to type 'null'.
2+
Type 'string' is not assignable to type 'null'.
3+
tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(8,7): error TS2322: Type 'string | null' is not assignable to type 'string'.
4+
Type 'null' is not assignable to type 'string'.
5+
tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts(11,7): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
6+
Type 'undefined' is not assignable to type 'string'.
7+
8+
9+
==== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts (3 errors) ====
10+
function test(strOrNull: string | null, strOrUndefined: string | undefined) {
11+
var str: string = "original";
12+
var nil: null;
13+
if (!Boolean(strOrNull)) {
14+
nil = strOrNull;
15+
~~~
16+
!!! error TS2322: Type 'string | null' is not assignable to type 'null'.
17+
!!! error TS2322: Type 'string' is not assignable to type 'null'.
18+
}
19+
else {
20+
str = strOrNull;
21+
~~~
22+
!!! error TS2322: Type 'string | null' is not assignable to type 'string'.
23+
!!! error TS2322: Type 'null' is not assignable to type 'string'.
24+
}
25+
if (Boolean(strOrUndefined)) {
26+
str = strOrUndefined;
27+
~~~
28+
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
29+
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
30+
}
31+
}
32+

tests/baselines/reference/typeGuardBoolean.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ function test(strOrNull: string | null, strOrUndefined: string | undefined) {
2020
>strOrNull : string | null
2121

2222
nil = strOrNull;
23-
>nil = strOrNull : null
23+
>nil = strOrNull : string | null
2424
>nil : null
25-
>strOrNull : null
25+
>strOrNull : string | null
2626
}
2727
else {
2828
str = strOrNull;
29-
>str = strOrNull : string
29+
>str = strOrNull : string | null
3030
>str : string
31-
>strOrNull : string
31+
>strOrNull : string | null
3232
}
3333
if (Boolean(strOrUndefined)) {
3434
>Boolean(strOrUndefined) : boolean
3535
>Boolean : BooleanConstructor
3636
>strOrUndefined : string | undefined
3737

3838
str = strOrUndefined;
39-
>str = strOrUndefined : string
39+
>str = strOrUndefined : string | undefined
4040
>str : string
41-
>strOrUndefined : string
41+
>strOrUndefined : string | undefined
4242
}
4343
}
4444

0 commit comments

Comments
 (0)