Skip to content

Commit 1652673

Browse files
committed
Use type guards in utils for known global types
1 parent 22a2a4e commit 1652673

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/utils/src/is.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @param wat A value to be checked.
88
* @returns A boolean representing the result.
99
*/
10-
export function isError(wat: any): boolean {
10+
export function isError(wat: any): wat is Error {
1111
switch (Object.prototype.toString.call(wat)) {
1212
case '[object Error]':
1313
return true;
@@ -27,7 +27,7 @@ export function isError(wat: any): boolean {
2727
* @param wat A value to be checked.
2828
* @returns A boolean representing the result.
2929
*/
30-
export function isErrorEvent(wat: any): boolean {
30+
export function isErrorEvent(wat: any): wat is ErrorEvent {
3131
return Object.prototype.toString.call(wat) === '[object ErrorEvent]';
3232
}
3333

@@ -38,7 +38,7 @@ export function isErrorEvent(wat: any): boolean {
3838
* @param wat A value to be checked.
3939
* @returns A boolean representing the result.
4040
*/
41-
export function isDOMError(wat: any): boolean {
41+
export function isDOMError(wat: any): wat is DOMError {
4242
return Object.prototype.toString.call(wat) === '[object DOMError]';
4343
}
4444

@@ -49,7 +49,7 @@ export function isDOMError(wat: any): boolean {
4949
* @param wat A value to be checked.
5050
* @returns A boolean representing the result.
5151
*/
52-
export function isDOMException(wat: any): boolean {
52+
export function isDOMException(wat: any): wat is DOMException {
5353
return Object.prototype.toString.call(wat) === '[object DOMException]';
5454
}
5555

@@ -60,7 +60,7 @@ export function isDOMException(wat: any): boolean {
6060
* @param wat A value to be checked.
6161
* @returns A boolean representing the result.
6262
*/
63-
export function isString(wat: any): boolean {
63+
export function isString(wat: any): wat is String {
6464
return Object.prototype.toString.call(wat) === '[object String]';
6565
}
6666

@@ -117,7 +117,7 @@ export function isElement(wat: any): wat is Element {
117117
* @param wat A value to be checked.
118118
* @returns A boolean representing the result.
119119
*/
120-
export function isRegExp(wat: any): boolean {
120+
export function isRegExp(wat: any): wat is RegExp {
121121
return Object.prototype.toString.call(wat) === '[object RegExp]';
122122
}
123123

0 commit comments

Comments
 (0)