Skip to content

Regression: yup.ObjectSchema<T> no longer assignable to ObjectSchema<any> (20260423.1) #3530

@modosc

Description

@modosc

apologies in advance for the claude output - lmk if there's anything else i can provide.

Versions

  • Last good: @typescript/native-preview@7.0.0-dev.20260422.1
  • First bad: @typescript/native-preview@7.0.0-dev.20260423.1
  • Stock tsc 5.x / 6.0 beta: accepts the program

Repro (2 files + 1 dep)

package.json

{
  "name": "tsgo-yup-repro",
  "private": true,
  "dependencies": { "yup": "1.7.1" },
  "devDependencies": { "@typescript/native-preview": "7.0.0-dev.20260423.1" }
}

tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "noEmit": true,
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "Bundler"
  },
  "include": ["repro.ts"]
}

repro.ts

import * as yup from 'yup';

const schema = yup.object({
  name: yup.string().required(),
});

declare function accepts<T extends yup.ObjectSchema<any>>(s: T): void;

accepts(schema);

Run npx tsgo -p tsconfig.json.

Observed (20260423.1)

repro.ts(9,9): error TS2345: Argument of type 'ObjectSchema<{ name: string; }, AnyObject, { name: undefined; }, "">' is not assignable to parameter of type 'ObjectSchema<any, AnyObject, any, "">'.
  The types returned by 'optional().strip(...).partial().__outputType' are incompatible between these types.
    Type '{ name?: string | undefined; } | undefined' is not assignable to type '{ [x: string]: any; [x: number]: any; [x: symbol]: any; }'.
      Type 'undefined' is not assignable to type '{ [x: string]: any; [x: number]: any; [x: symbol]: any; }'.

Exit code 2.

Expected
Clean exit, same as 20260422.1 and stock tsc.

Real-world impact
Breaks every call of @hookform/resolvers/yup's yupResolver, whose signature is <T extends Yup.ObjectSchema<any>>(schema: T, ...). In our codebase: 103 call sites across 40+ files, zero before the bump.

Analysis
The RHS __outputType in the error message resolves to {[x: string]: any; [x: number]: any; [x: symbol]: any} (yup's AnyObject) rather than any. undefined (from optional()) doesn't fit AnyObject, hence the error.

Likely cause: when instantiating ObjectSchema<any> where the type parameter is TIn extends Maybe<AnyObject> (= AnyObject | null | undefined), 20260423.1 resolves the any argument up to its constraint (AnyObject) somewhere along the optional().strip().partial() method chain, where 20260422.1 kept it as any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions