Skip to content

Use type guards in utils for known global types #2277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/utils/src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @param wat A value to be checked.
* @returns A boolean representing the result.
*/
export function isError(wat: any): boolean {
export function isError(wat: any): wat is Error {
switch (Object.prototype.toString.call(wat)) {
case '[object Error]':
return true;
Expand All @@ -27,7 +27,7 @@ export function isError(wat: any): boolean {
* @param wat A value to be checked.
* @returns A boolean representing the result.
*/
export function isErrorEvent(wat: any): boolean {
export function isErrorEvent(wat: any): wat is ErrorEvent {
return Object.prototype.toString.call(wat) === '[object ErrorEvent]';
}

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

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

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

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

Expand Down