Skip to content

Commit 8ab5fcd

Browse files
correctly handle null when type-guarding promises and observables (#2751)
1 parent cdc44aa commit 8ab5fcd

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphiql/toolkit': patch
3+
---
4+
5+
Correctly handle `null` in type-guard functions for `Promise` and `Observable`

packages/graphiql-toolkit/src/async-helpers/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66

77
// Duck-type promise detection.
88
export function isPromise<T>(value: Promise<T> | any): value is Promise<T> {
9-
return typeof value === 'object' && typeof value.then === 'function';
9+
return (
10+
typeof value === 'object' &&
11+
value !== null &&
12+
typeof value.then === 'function'
13+
);
1014
}
1115

1216
// Duck-type Observable.take(1).toPromise()
@@ -29,6 +33,7 @@ function observableToPromise<T>(observable: Observable<T>): Promise<T> {
2933
export function isObservable<T>(value: any): value is Observable<T> {
3034
return (
3135
typeof value === 'object' &&
36+
value !== null &&
3237
'subscribe' in value &&
3338
typeof value.subscribe === 'function'
3439
);

0 commit comments

Comments
 (0)