Skip to content

7.1 regression: circular type alias accepts an assignment it should reject (opposite of #64891) #64930

Open

Description

Search Terms

circular type alias variance, missing TS2322, unrelated type arguments assignable, 7.1 regression, #64891

Version & Regression Information

I bisected it with the nightlies: 7.1.0-dev.20260805.1 (built from 12318e599) reports the error, and 7.1.0-dev.20260806.1 (built from 86cc4767d, the #4820 merge) doesn't.

Playground Link

No response

Code

type Params<T, K> = { config: Config<T, K> };
type Handler<T, K> = (params: Params<T, K>) => void;
type Config<T, K> = { read: (item: T) => void; handler: Handler<T, K> };

declare const a: Handler<string, string>;
export const b: Handler<number, string> = a; // should be TS2322
{ "compilerOptions": { "strict": true, "noEmit": true, "types": [] }, "files": ["a.ts"] }

Actual behavior

No errors. A handler that reads strings is accepted where one that reads numbers is expected.

It's not just close types either: Handler<boolean, { x: 1 }> is accepted too.

Expected behavior

TS2322 on the last line, same as 6.0.3 and 7.0.2.

Additional information about the issue

Hi there!

Some context on how I found this: I've been testing out the latest 7.1 nightlies and I'm super excited about them, mainly for the memory and CPU speedups. We have a very large TypeScript monorepo in production, so those gains make a real difference for us.

While digging into #64891 I found the opposite case, and I think it's the other half of the same bug. That issue is about 7.1 rejecting code it should accept. This one is the opposite, it accepts code it should reject, which is a bit scarier because nothing tells you it happened.

Here's what I see with tsc -p . (same result on every run):

Build This repro #64891 repro
6.0.3 TS2322 (correct) no errors (correct)
7.0.2 TS2322 (correct) no errors (correct)
7.1.0-dev.20261022.1 no errors (wrong) TS2322 (wrong)
#64893 (6e72aa7, built locally) TS2322 (correct) no errors (correct)

A few other things I noticed while narrowing it down:

Thanks for all the work on 7.x, it's been great so far!

Activity

  1. Sipixer commented on Nov 18, 2026

    @Sipixer

    Note

    🤖 Written with Claude Opus 5.5, reviewed and posted by me.

    This also breaks @tanstack/db 1.0. Its collection types have the same cycle (Collection → CollectionConfig → onDelete: DeleteMutationFn<T, TKey> → Collection), so on 7.1 every collection without a schema is typed Collection<never, …>. In one production app that is about 2,400 errors, and none on 7.0.2.

    import { collectionOptions, type DbClient } from '@tanstack/db'
    type Row = { id: string }
    const descriptor = collectionOptions('rows', (_client: DbClient) => ({
      getKey: (row: Row) => row.id,
      sync: { sync: () => {} },
    }))
    declare const client: DbClient
    const rows = client.collection(descriptor)
    // 7.0.2: Collection<Row, …>    7.1: Collection<never, …>

    It still reproduces on 7.1.0-dev.20261118.1, after #65030, and bisects to the same nightly as the original report.

  2. added
    Domain: check: Order Dependence
    on Nov 22, 2026
  3. MAST1999 commented on Nov 23, 2026

    @MAST1999

    Confirmed on typescript@7.1.0-beta (tsc --noEmit -p .): the repro above gives no error, and both workarounds restore TS2322 on 7.1.0-beta.

    7.0.2 7.1.0-beta
    repro as posted error no error
    Handler declared before Params error error
    type Handler<in out T, K> error error

    How it breaks @tanstack/db 1.0.0-rc.1.5

    DbClient.collection() declares a schema-carrying overload first and a schema-less one second (abridged):

    collection<T extends StandardSchemaV1, …>(options: CollectionOptions<InferSchemaOutput<T>, TKey, T, TUtils>, …): Collection<InferSchemaOutput<T>, …>;
    collection<T extends object, …>(options: CollectionOptions<T, TKey, never, TUtils>, …): Collection<T, …>;

    Because InsertMutationFn<A> is now assignable to InsertMutationFn<B> for any A and B, the first overload matches with T = never, the second is never reached, and every collection is Collection<never, …>:

    import type { CollectionOptions, DbClient } from "@tanstack/react-db";
    
    declare const dbClient: DbClient;
    declare const d: CollectionOptions<{ readonly id: string }, string, never, Record<string, never>>;
    export const show: "SHOW" = dbClient.collection(d);
    7.0.2:      Type 'Collection<{ readonly id: string; }, string, Record<string, never>, never, { readonly id: string; }> & NonSingleResult'
    7.1.0-beta: Type 'Collection<never, string, Record<string, never>, never, never> & NonSingleResult'
    

    On our app that is 538 errors on 7.1.0-beta and 0 on 7.0.2.

    Workaround for @tanstack/db users

    Mark the three hook aliases invariant (pnpm patch; dist/esm/types.d.ts and dist/cjs/types.d.cts). On the same app this gives 0 errors on both 7.0.2 and 7.1.0-beta.

    export type InsertMutationFn<in out T extends object = Record<string, unknown>, …> = …;
    export type UpdateMutationFn<in out T extends object = Record<string, unknown>, …> = …;
    export type DeleteMutationFn<in out T extends object = Record<string, unknown>, …> = …;

    Note

    🤖 Drafted with AI assistance and posted on behalf of the account owner, who directed and approved this comment.

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

Metadata

Metadata

Labels

BugDomain: check: Order Dependence

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions