Skip to content

Commit ee9454a

Browse files
authored
Add check for nullable value
1 parent 9c89b50 commit ee9454a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/api/tojs.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ function toJSHelper(source, options: ToJSOptions, __alreadySeen: Map<any, any>)
2727
if (!options.recurseEverything && !isObservable(source)) return source
2828

2929
if (typeof source !== "object") return source
30+
31+
// Directly return null if source is null
32+
if (source === null) return null
3033

3134
// Directly return the Date object itself if contained in the observable
3235
if (source instanceof Date) return source
3336

3437
if (isObservableValue(source)) return toJSHelper(source.get(), options!, __alreadySeen)
3538

3639
// make sure we track the keys of the object
37-
if (isObservable(source)) {
38-
keys(source)
39-
}
40+
if (isObservable(source)) keys(source)
4041

4142
const detectCycles = options.detectCycles === true
4243

0 commit comments

Comments
 (0)