Skip to content

A generic alias in a cycle is treated as assignable for any type arguments, so @tanstack/db collection.update() draft becomes never #1018

Open

Description

@Jaime02

Version: tsrs 0.25.0-ts7.1.0-beta (Version 7.1.0-beta, microsoft/TypeScript@3e9236361fa9), Windows x64. Compared with typescript@7.0.2 (tsc).

Problem

For a generic alias whose parameters pass through a cycle (InsertFn → Params → Collection → InsertFn), tsrs treats two instantiations as assignable whatever their type arguments are, where tsc compares them. The result depends on declaration order. It was found through @tanstack/db, where it makes the draft of collection.update(key, (draft) => …) resolve to never (see the end).

Minimal repro (one file, no dependencies)

tsconfig.json:

{ "compilerOptions": { "strict": true, "noEmit": true, "target": "es2022", "module": "esnext", "moduleResolution": "bundler", "types": [] }, "include": ["index.ts"] }

index.ts:

type Params<T, K> = { collection: Collection<T, K> };
type InsertFn<T, K> = (params: Params<T, K>) => void;
interface Collection<T, K> {
  onInsert: InsertFn<T, K>;
  item: T;
}

type A = { id: number };
type B = { name: string };

declare const a: InsertFn<A, 1>;
declare const never_: InsertFn<never, 1>;

export const unrelated: InsertFn<B, 1> = a; // tsc: TS2322
export const fromNever: InsertFn<A, 1> = never_; // tsc: TS2322
$ tsc -p .    # typescript 7.0.2
index.ts(14,14): error TS2322: Type 'InsertFn<A, 1>' is not assignable to type 'InsertFn<B, 1>'.
index.ts(15,14): error TS2322: Type 'InsertFn<never, 1>' is not assignable to type 'InsertFn<A, 1>'.
$ tsrs -p .   # no output, exit 0

What narrows it

  • Declaration order. Moving type InsertFn above type Params makes tsrs report both errors, like tsc.
  • Two type parameters. With a single type parameter (InsertFn<T>, Params<T>, Collection<T>), tsrs reports the errors correctly. K is passed through the cycle but never read by a member, and the bug needs it.
  • Only the alias comparison is wrong. Comparing Params<A, 1> to Params<B, 1> or Collection<A, 1> to Collection<B, 1> directly is rejected correctly. Only InsertFn<…> against InsertFn<…> is accepted. A structurally identical alias, type F<T, K> = (p: Params<T, K>) => void, is also rejected, so it only affects the alias that is part of the cycle.
  • The entity type is ignored. InsertFn<A, 1> is accepted for InsertFn<B, 1> (unrelated) and InsertFn<never, 1> for InsertFn<A, 1>. The behaviour is the same as if the variance of T for InsertFn had been computed as independent or bivariant while the cycle was still being resolved, and that result was kept.

I have not confirmed the cause in the checker. The variance explanation is my reading of the symptoms.

Effect on real code

In @tanstack/db@1.0.0-rc.1.5 the same cycle is InsertMutationFn → InsertMutationFnParams → Collection → CollectionConfig.onInsert (UpdateMutationFn and DeleteMutationFn have the same issue). DbClient.collection(options) tries an overload that needs CollectionOptions<InferSchemaOutput<T>, …> with T inferred as never. tsc rejects that overload because the handlers differ and falls back to the plain-object overload. tsrs accepts it, so the result is Collection<never, …> and draft is never:

import { DbClient, collectionOptions } from "@tanstack/db";
import type { CollectionConfig } from "@tanstack/db";
import { z } from "zod";

function wrap<TSchema extends z.ZodType<object>, TKey extends string | number>(
  config: Omit<CollectionConfig<z.output<TSchema>, TKey, TSchema>, "sync"> & { schema: TSchema },
): CollectionConfig<z.output<TSchema>, TKey, TSchema> {
  return { ...config, sync: { sync: () => {} } };
}

const schema = z.object({ id: z.number(), quantity: z.number() });
const linesOptions = collectionOptions("lines", () => wrap({ id: "lines", schema, getKey: (item) => item.id }));

new DbClient().collection(linesOptions).update(1, (draft) => {
  draft.quantity = 2; // tsrs: TS2339 Property 'quantity' does not exist on type 'never'. tsc: no error
});

In an app with about 580 files, this pattern gives 13× TS2339 and 2× TS2353 (… does not exist in type 'never[]') under tsrs and tsrs-lint --type-check. tsc and tsgolint report none.

I reduced this from the full @tanstack/db declaration files by hand. An automatic reducer that kept the output of both compilers identical also confirmed that no other file is needed.

Activity

  1. oxc-captain commented on Nov 17, 2026

    @oxc-captain
    Contributor
    • Reproduced: Skipped — automated triage could not be completed (report.md was missing)
    • Exploration: No
    • Unit Test: No — automated triage could not be completed
    • Priority: Priority P3: Narrow or low-impact issue. The priority could not be determined because the triage report was not generated.

    Automated triage was unable to produce a report for this issue because report.md was missing from the triage directory. No reproduction, diagnosis, or fix exploration could be performed as part of comment generation.

    I was unable to determine the cause of this issue. Please re-run the triage workflow or provide the generated triage report so this issue can be evaluated.

    Full Triage Report

    Automated triage did not produce a report (report.md was missing).

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  2. changed the title [-]Draft parameter of @tanstack/db collection.update() inferred as never (false TS2339); tsc reports nothing[/-] [+]A generic alias in a cycle is treated as assignable for any type arguments, so @tanstack/db collection.update() draft becomes never[/+] on Nov 18, 2026
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

    triage: unable to reproduceAutomated investigation could not reproduce the report

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions