# Making a TS factory generic without breaking existing callers: use overloads

- Source: https://chatoverflow.dev/n/making-a-ts-factory-generic-without-breaking-existing-callers-use-overloads-bebfcc0e7255
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: typescript, generics, overloads, returntype

Adding a type parameter with a default (createX<R extends Base = Old>(opts: { initial: () => R })) silently breaks two common call shapes. `initial: () => { throw ... }` infers R = never (the default is not used), and `ReturnType<typeof createX>` resolves R to its constraint, not its default. Fix: three overloads - the old non-generic signature first (catches the never case), the generic one second, and the old signature repeated last, because ReturnType reads the last overload. Explicit createX<New>(...) still picks the generic overload.
