You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug with type argument inference if it has default value = undefined and actual value is object with non-arrow function #62995
functionmake<T,S=T,D=undefined>(value: T,options: NewOptions<T,S,D>){return{v: value,data: options?.data,sourceValue: options?.sourceValue??value,finaleValue: options?.finaleValue,};}exporttypeNewOptions<T,S,D>={finaleValue?: T,sourceValue?: S,data: D,};constinstance_withError=make(0,{// Error here: `Type '{ test(): number; }' is not assignable to type 'undefined'.(2322)`?data: {test(){return123;},},});constdata={test(){return123;},};// no error hereconstinstance1=make(0,{// data is not inline object, BUT object with non-arrow function
data,sourceValue: 'test',finaleValue: 1,});// no error hereconstinstance2=make(0,{// data is inline object, BUT object with arrow functiondata: {test: ()=>{return123;},},sourceValue: 1,finaleValue: 2,});constsV1=instance2.sourceValue;// ^?constv1=instance2.v;// ^?constsV2=instance1.sourceValue;// ^?constv2=instance1.v;// ^?// Should be `{ test(): number; }`constdata_invalid=instance_withError.data;// ^?// Should be `{ test(): number; }`constdata1=instance1.data;// ^?// Should be `{ test: () => number; }`constdata2=instance2.data;// ^?
🙁 Actual behavior
An error occurs:
Type '{ test(): number; }' is not assignable to type 'undefined'.(2322)
declarefunctionmake<D=undefined>(options: D): any;// cant infermake({test(){return123;},});// can explictly callmake<{test(): number}>({test(){return123;},})// can infer with arrow functionmake({test: ()=>{return123;},});
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)typeContext<MextendsReadonlyArray<ModuleConstructor<General>>,KextendsKeys<InstanceEach<M>[number]>,Prextendsobject={},>=MergeResult<M,K,Pr>&{__assign__: (obj: Partial<MergeResult<M,K,Pr>>)=>Context<M,K,Pr>;};declarefunctioncreateContext<MextendsReadonlyArray<ModuleConstructor<Context<M,K,Pr>>>,KextendsKeys<InstanceEach<M>[number]>,Prextendsobject={},>(classes: M,options: {preMerge?: Pr;mergeKeys: ReadonlyArray<K>;},): Context<M,K,Pr>;
Test code (simplified):
// Works (arrow function)constcontext=createContext(allModules,{mergeKeys: ['settings','root','events','i18n'],preMerge: {registerEvent: (ref: EventRef)=>this.registerEvent(ref),},}).__assign__({settings: this.settings});// Works (hoisting)constpreMerge={registerEvent: this.registerEvent.bind(this),};constcontext=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` typeconstcontext=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?
Activity
nmain commentedon Jan 16, 2026
There's a lot of extra fluff in that repro, isn't it just this?
Playground
MartinJohns commentedon Jan 16, 2026
Likely a duplicate of #47599.
termi commentedon Jan 16, 2026
The reason why my example has 3 generic parameters
is to show that
D=undefineddefault value is necessary here and cannot be removed.Is you case
we can just remove
=undefinedand all will work fine.termi commentedon Jan 16, 2026
It's related, but not duplicate.
In my case, adding
=undefinedin generic parameter causes a problem.Andarist commentedon Jan 16, 2026
This is already fixed by #62243 . You can try out nightly build.
RyanCavanaugh commentedon Jan 16, 2026
Confirmed in nightly playground
hesprs commentedon Jun 22, 2026
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:
Test code (simplified):
Since this is a closed issue, do I need to open a new one, or report in #47599, or do nothing?
RyanCavanaugh commentedon Jun 24, 2026
Hēsperus (@hesprs) please log a new issue, thanks