Skip to content

Commit d3c572c

Browse files
author
Forbes Lindesay
committed
Allow Boolean() to be used to perform a null check
1 parent b2b360a commit d3c572c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/lib/es5.d.ts

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @strictNullChecks: true
2+
function test(strOrNull: string | null, strOrUndefined: string | undefined) {
3+
var str: string = "original";
4+
var nil: null;
5+
if (!Boolean(strOrNull)) {
6+
nil = strOrNull;
7+
}
8+
else {
9+
str = strOrNull;
10+
}
11+
if (Boolean(strOrUndefined)) {
12+
str = strOrUndefined;
13+
}
14+
}

0 commit comments

Comments
 (0)