Which fix removes the bug?
interface Opts { retries?: number }
function run(o: Opts) {
const r = o.retries || 3;
return r;
}
- Default with
o.retries ?? 3instead - Default with
o.retries && 3instead - Make
retriesrequired in the interface - Change the return type to
number | undefined
An explicit 0 is falsy and gets replaced by 3; ?? only defaults on null or undefined.
Play Problem Solving ▸