Repository navigation
Bug with type argument inference if it has default value = undefined and actual value is object with non-arrow function #62995
Description
Activity
There's a lot of extra fluff in that repro, isn't it just this?
declare function make<D=undefined>(options: D): any; // cant infer make({ test() { return 123; }, }); // can explictly call make<{ test(): number }>({ test() { return 123; }, }) // can infer with arrow function make({ test: () => { return 123; }, });
Reacted by Martin Johns and Егор ХалимоненкоMartinJohns commented
on Jan 16, 2026 ContributorMore actionsLikely a duplicate of #47599.
Reacted by Егор ХалимоненкоThere's a lot of extra fluff in that repro, isn't it just this?
The reason why my example has 3 generic parameters
declare function make<T, S=T, D=undefined>(value: T, options: NewOptions<T, S, D>);
is to show that
D=undefineddefault value is necessary here and cannot be removed.Is you case
declare function make<D=undefined>(options: D): any;
we can just remove
=undefinedand all will work fine.Likely a duplicate of #47599.
It's related, but not duplicate.
In my case, adding=undefinedin generic parameter causes a problem.Andarist commented
on Jan 16, 2026 ContributorMore actionsThis is already fixed by #62243 . You can try out nightly build.
Reacted by Ryan Cavanaugh and Егор Халимоненко- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jan 16, 2026 RyanCavanaugh commented
on Jan 16, 2026 MemberMore actionsConfirmed in nightly playground
I don't consider it is fixed. Exact situation here, errors still. Tried both on TS 6.0.3 and latest TSGO.
Simplified package code:
// ... (A ton of generics gymnastics) type Context< M extends ReadonlyArray<ModuleConstructor<General>>, K extends Keys<InstanceEach<M>[number]>, Pr extends object = {}, > = MergeResult<M, K, Pr> & { __assign__: (obj: Partial<MergeResult<M, K, Pr>>) => Context<M, K, Pr>; }; declare function createContext< M extends ReadonlyArray<ModuleConstructor<Context<M, K, Pr>>>, K extends Keys<InstanceEach<M>[number]>, Pr extends object = {}, >( classes: M, options: { preMerge?: Pr; mergeKeys: ReadonlyArray<K>; }, ): Context<M, K, Pr>;
Test code (simplified):
// Works (arrow function) const context = createContext(allModules, { mergeKeys: ['settings', 'root', 'events', 'i18n'], preMerge: { registerEvent: (ref: EventRef) => this.registerEvent(ref), }, }).__assign__({ settings: this.settings }); // Works (hoisting) const preMerge = { registerEvent: this.registerEvent.bind(this), }; const context = createContext(allModules, { mergeKeys: ['settings', 'root', 'events', 'i18n'], preMerge, }).__assign__({ settings: this.settings }); // Fails, failure message shows that `Pr` is degraded to `{}` instead of exact `preMerge` type const context = createContext(allModules, { mergeKeys: ['settings', 'root', 'events', 'i18n'], preMerge: { registerEvent: this.registerEvent.bind(this), }, }).__assign__({ settings: this.settings });
Since this is a closed issue, do I need to open a new one, or report in #47599, or do nothing?
RyanCavanaugh commented
on Jun 24, 2026 MemberMore actionsHēsperus (@hesprs) please log a new issue, thanks
There is a difference in how TypeScript infers the type automatically based on type of the argument we pass in:
The error is reproduced if generic parameter has default value
undefined(this is mandatory in my case.)🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
💻 Code
This issue with function:
🙁 Actual behavior
Type '{ test(): number; }' is not assignable to type 'undefined'.(2322)
datatype isundefined🙂 Expected behavior
datatype is{ test(): number; }