Skip to content

() => NoInfer<T> rejects async () => Promise.reject(...), which () => T accepts #65742

Backlog

Description

@jordanburke

TypeScript Version

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):

declare function getOr<T>(value: T, fallback: () => NoInfer<T>): T
declare function getOrPlain<T>(value: T, fallback: () => T): T
declare const value: number | PromiseLike<number>

// Error: Type 'Promise<number | NoInfer<number | PromiseLike<number>>>' is not assignable to type 'number | PromiseLike<number>'.
export const bad1 = getOr(value, async () => Promise.reject(new Error("x")))

// All of these compile:
export const ok1 = getOrPlain(value, async () => Promise.reject(new Error("x"))) // no NoInfer
export const ok2 = getOr(value, () => Promise.reject(new Error("x"))) // callback not async
export const ok3 = getOr(value, async () => Promise.reject<number>(new Error("x"))) // explicit type argument

// The same thing without getOr:
type R = number | PromiseLike<number>
export const bad2: () => NoInfer<R> = async () => Promise.reject(new Error("x")) // error
export const ok4: () => R = async () => Promise.reject(new Error("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.

Possibly related: #61076.

Agent Info

Claude Code 2.1.332 + Claude Opus 5.5 + Skill Version 1.0

Activity

  1. RyanCavanaugh commented on Nov 30, 2026

    @RyanCavanaugh
    Member

    Why are you writing U | NoInfer<U> in the first place?

  2. changed the title [-]NoInfer in a callback's return type leaks into the inferred type argument when the callback is async[/-] [+]`() => NoInfer<T>` rejects `async () => Promise.reject(...)`, which `() => T` accepts[/+] on Nov 30, 2026
  3. jordanburke commented on Nov 30, 2026

    @jordanburke
    Author

    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:

    declare function fold<A, B = A>(onLeft: () => A | NoInfer<B>, onRight: () => B | NoInfer<A>): A | B

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions