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
() => NoInfer<T> rejects async () => Promise.reject(...), which () => T accepts #65742
The tested TypeScript version is 7.1.0-dev.20261130.1. It also reproduces on 5.4.5 and 6.0.3.
User Goal
The user maintains a library whose fold-style function uses NoInfer in its callbacks' return types. An async callback that returns Promise.reject(...) fails to compile there, and the user asked me to narrow it down to a TypeScript repro and report it.
Setup and Action
Run tsc --strict --target es2022 on this file (Playground):
declarefunctiongetOr<T>(value: T,fallback: ()=>NoInfer<T>): TdeclarefunctiongetOrPlain<T>(value: T,fallback: ()=>T): Tdeclareconstvalue: number|PromiseLike<number>// Error: Type 'Promise<number | NoInfer<number | PromiseLike<number>>>' is not assignable to type 'number | PromiseLike<number>'.exportconstbad1=getOr(value,async()=>Promise.reject(newError("x")))// All of these compile:exportconstok1=getOrPlain(value,async()=>Promise.reject(newError("x")))// no NoInferexportconstok2=getOr(value,()=>Promise.reject(newError("x")))// callback not asyncexportconstok3=getOr(value,async()=>Promise.reject<number>(newError("x")))// explicit type argument// The same thing without getOr:typeR=number|PromiseLike<number>exportconstbad2: ()=>NoInfer<R>=async()=>Promise.reject(newError("x"))// errorexportconstok4: ()=>R=async()=>Promise.reject(newError("x"))
T has to include both a value and a promise of it. In the library, that happens when fold is returned from an async function.
Expected and Actual Behavior
What actually happened: bad1 fails with error TS2322: Type 'Promise<number | NoInfer<number | PromiseLike<number>>>' is not assignable to type 'number | PromiseLike<number>'.bad2 fails with Type 'Promise<number | NoInfer<R>>' is not assignable to type 'R'.
What I expected: bad1 and bad2 compile, as ok1 and ok4 do. NoInfer<R> should check like R.
Sorry, I shrank that repro too far. The real code is a two-type-parameter fold, where each callback can also return the other's type without inferring from it:
I've updated the issue with a repro that doesn't need U | NoInfer<U>. () => NoInfer<T> rejects async () => Promise.reject(...), which () => T accepts, when T mixes a value and a promise, like number | PromiseLike<number>. Our code gets a T like that when fold is returned from an async function.
Activity
RyanCavanaugh commentedon Nov 30, 2026
Why are you writing
U | NoInfer<U>in the first place?[-]NoInfer in a callback's return type leaks into the inferred type argument when the callback is async[/-]jordanburke commentedon Nov 30, 2026
Sorry, I shrank that repro too far. The real code is a two-type-parameter
fold, where each callback can also return the other's type without inferring from it:I've updated the issue with a repro that doesn't need
U | NoInfer<U>.() => NoInfer<T>rejectsasync () => Promise.reject(...), which() => Taccepts, whenTmixes a value and a promise, likenumber | PromiseLike<number>. Our code gets aTlike that whenfoldis returned from an async function.