Repository navigation
Description
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 InsertFnabovetype Paramsmakestsrsreport both errors, liketsc. - Two type parameters. With a single type parameter (
InsertFn<T>,Params<T>,Collection<T>),tsrsreports the errors correctly.Kis 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>toParams<B, 1>orCollection<A, 1>toCollection<B, 1>directly is rejected correctly. OnlyInsertFn<…>againstInsertFn<…>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 forInsertFn<B, 1>(unrelated) andInsertFn<never, 1>forInsertFn<A, 1>. The behaviour is the same as if the variance ofTforInsertFnhad 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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
oxc-captain commentedon Nov 17, 2026
Automated triage was unable to produce a report for this issue because
report.mdwas 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.mdwas 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.
[-]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[/+]