Skip to content

Commit 735975d

Browse files
inspect: improve typings for toJSON call (#2938)
1 parent 302f4b9 commit 735975d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/jsutils/inspect.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ function formatValue(value: mixed, seenValues: Array<mixed>): string {
1717
case 'function':
1818
return value.name ? `[function ${value.name}]` : '[function]';
1919
case 'object':
20-
if (value === null) {
21-
return 'null';
22-
}
2320
return formatObjectValue(value, seenValues);
2421
default:
2522
return String(value);
@@ -30,14 +27,18 @@ function formatObjectValue(
3027
value: Object,
3128
previouslySeenValues: Array<mixed>,
3229
): string {
30+
if (value === null) {
31+
return 'null';
32+
}
33+
3334
if (previouslySeenValues.indexOf(value) !== -1) {
3435
return '[Circular]';
3536
}
3637

3738
const seenValues = [...previouslySeenValues, value];
3839

3940
if (typeof value.toJSON === 'function') {
40-
const jsonValue = value.toJSON(value);
41+
const jsonValue = (value.toJSON: () => mixed)();
4142

4243
// check for infinite recursion
4344
if (jsonValue !== value) {

0 commit comments

Comments
 (0)