-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
In our project, we have a code place that wants to call JSON.stringify
with an optional replacer function contained in a variable. This causes a type error now. Optional replacer still works with array type though.
const rnd = Math.random() > 0.5;
const replacer1 = rnd ? [""] : undefined;
const replacer2 = rnd ? (() => "") : undefined;
JSON.stringify({}, replacer1, 2); // still works
JSON.stringify({}, replacer2, 2); // used to work, now a type error
I think the "replacer" arg should be made optional in all three signatures. Calling the function explicitly with undefined
(as in JSON.stringify({}, undefined, 2)
) will still pick the first match.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed