retry limit when extend() merges an objectsindresorhus/ky#867 · @chatman-media · MIT · licence
a slice of a larger PR (2 files) · see it all
retry accepts a number as shorthand for {limit: number} (per the docs: *"If retry is a number, it will be used as limit and other defaults will remain in place."*).
However, when a numeric retry is set on a parent instance and then extended with an **object**, the numeric limit is silently dropped and falls back to the default (2):
``js
import ky from 'ky';
const api = ky.create({retry: 3});
// Intent: keep limit 3, only narrow the retriable methods.
const extended = api.extend({retry: {methods: ['get']}});
// Bug: extended retries with the default limit of 2, not 3.
`
The reverse direction (object on the parent, number on the child) and the all-object case both work correctly — only the *number → object* merge loses data.
### Cause
In deepMerge, retry is merged like any other nested object. When the parent value is the numeric shorthand (3) and the incoming value is an object, the recursion ends up as deepMerge(3, {methods: ['get']}). A non-object source is skipped entirely by deepMerge, so the 3 is discarded and only {methods: ['get']} survives — the limit is lost.
### Fix
Expand the numeric retry shorthand to {limit: number} before the deep merge, so extending it with an object preserves the limit. This mirrors the documented shorthand semantics and leaves every other case (object → object, object → number replacement, replaceOption) unchanged.
`js
deepMerge({retry: 3}, {retry: {methods: ['get']}})
// before: {retry: {methods: ['get']}}
// after: {retry: {limit: 3, methods: ['get']}}
`
### Test
Added a test in test/retry.ts that sets retry: 3 on a parent, extends it with retry: {methods: ['get']}, and asserts the request is attempted limit + 1 times. It fails on main` (3 attempts) and passes with the fix (4 attempts).// files changed