Repository navigation
Description
Search Terms
circular type alias variance, missing TS2322, unrelated type arguments assignable, 7.1 regression, #64891
Version & Regression Information
- This changed between versions 7.0.2 and 7.1.0-dev.20261022.1
- This changed in commit or PR Order variance computation by associated type symbol typescript-go#4820
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:
-
It needs two type parameters. With only
T, every build reports the error. -
If I move
HandleraboveParams, the nightly reports the error again. -
fix(checker): resolve TS2322 regression in circular generic interface variance calculation #64893 fixes both repros, but the result still depends on what gets checked first. If
Paramsis compared beforeHandler, every build I tried misses theHandlererror, fix(checker): resolve TS2322 regression in circular generic interface variance calculation #64893 included:declare const p: Params<string, string>; export const q: Params<number, string> = p; // TS2322 everywhere declare const a: Handler<string, string>; export const b: Handler<number, string> = a; // missed everywhere
So I'm not sure fix(checker): resolve TS2322 regression in circular generic interface variance calculation #64893 is the full fix, but it does get things back to how 7.0.2 behaves.
Thanks for all the work on 7.x, it's been great so far!
Activity
Sipixer commentedon Nov 18, 2026
Note
🤖 Written with Claude Opus 5.5, reviewed and posted by me.
This also breaks
@tanstack/db1.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 typedCollection<never, …>. In one production app that is about 2,400 errors, and none on 7.0.2.It still reproduces on
7.1.0-dev.20261118.1, after #65030, and bisects to the same nightly as the original report.MAST1999 commentedon Nov 23, 2026
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.Handlerdeclared beforeParamstype Handler<in out T, K>How it breaks
@tanstack/db1.0.0-rc.1.5DbClient.collection()declares a schema-carrying overload first and a schema-less one second (abridged):Because
InsertMutationFn<A>is now assignable toInsertMutationFn<B>for anyAandB, the first overload matches withT = never, the second is never reached, and every collection isCollection<never, …>:On our app that is 538 errors on 7.1.0-beta and 0 on 7.0.2.
Workaround for
@tanstack/dbusersMark the three hook aliases invariant (
pnpm patch;dist/esm/types.d.tsanddist/cjs/types.d.cts). On the same app this gives 0 errors on both 7.0.2 and 7.1.0-beta.Note
🤖 Drafted with AI assistance and posted on behalf of the account owner, who directed and approved this comment.