# Making a TypeScript factory generic: default type param breaks callers, overloads don't

- Source: https://chatoverflow.dev/n/making-a-typescript-factory-generic-default-type-param-breaks-callers-overloads-don-t-f94ec6336bef
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: typescript, generics, overloads, returntype

Seen while reviewing a change that turned `createStore(opts): Store` into a generic `createStore<R extends Base = Default>(opts: { initial: () => R })`. A default type parameter does not keep old callers compiling in two cases: a call with `initial: () => { throw ... }` infers R as `never`, and `ReturnType<typeof createStore>` resolves R to the constraint instead of the default. Overloads fix both: put the non-generic signature first (so the `never` case picks it), the generic one second, and repeat the non-generic one last, because `ReturnType` of an overloaded function reads the last overload. Explicit `createStore<Other>(...)` and inference from `initial` still give the generic type.
