Skip to content

TS2322 missed with 3+ checkers: keyof depends on checker assignment when an interface's index signature uses its own keyof #65543

Description

@blickly

🔎 Search Terms

keyof index signature, index signature refers to its own keyof, self-referential index signature, circular keyof, Props[keyof Props], --checkers, --singleThreaded, checker assignment, check order, order dependent, TS2322, checker count dependent

🕗 Version & Regression Information

  • This is the behavior in every TS 7 version I tried, back to 7.0.2. 6.0.3 has one checker and reports the error.

⏯ Playground Link

https://tsgo.sxzz.dev/#eNptk0+P2jAQxb/KyD0AUjb8WYpKVlXVVS+ttGpVkHogHJxkQtxN7Mh22EUs371jB1BS9uTgef69N2NzZDmLNhuWKmmaCnVoDQvYeAx/hC0gZmmB6TNqE7MIpgFYs1OgsVbaGhi+OM3dnRFyV+K60MgzzMAqNYpiSQyADna4DKbzUQSotdKwXs3uZ7MI1ocaYTAZgDAglQVujNhJnpRIHLC++owHlcMvrWozCD34nXBzGNoCIcOcN6UdBSDsNahUratpT3d4FLBCA6pxzkTkMYM3WhNaRQ62oFi5KHFAytYMChLy0vV68LR2P4Pa8ajPALjMHM1YTYMhnGyqhA4SjzLRcTmwIU0yhUU4Ce+vKSm+B/qoIawQoRKpVkblduzmtEq1qO2HxXy5/ESdiMqda2d0PLdzglyrihoIxz5PzB5iGUt89VJ3G9a1H/Vm8BkmpGLbYMMuTdAb6OMfucGvgV8euy4JbfznIqRFnfMUz3h8tSgz00ccYwmw8VHaOW2jVr7pJNsS9nRO5o3aZDc+nkwh+ZcL7QFO7+Q5W0NCuvZSvM7z6T6UzMUu/GuUJBMfkJ6Yqmq6f/2ztoKm516ar7ia5XqH1m3FDA3Z0XdwKVYqa0psi7VGg3qPN+XfaFTZOHIrTBqZkVlH59pJvYfVDV630Tx5wHfXm6pv6vSgvwndQjNhusEyTEuu+cW0d0y7PHv8QSN4uubvKXp/Obd5Ol/RNmApixhNbk/LbDJbhNNp+JF+v7Ao56XB0z/qvXfZ

💻 Code

bases.ts

export interface BaseA { a?: string; }
export interface BaseB { b?: number; }

props.ts

import type { BaseA, BaseB } from "./bases";

export interface Props extends BaseA, BaseB {
  [key: string]: Props[keyof Props];
}

consumer.ts

import type { Props } from "./props";

export const key: keyof Props = 0;

Compile the three files together, for example tsc --noEmit --checkers 1 bases.ts props.ts consumer.ts.

🙁 Actual behavior

With 3 or more checkers, including the default of 4, there's no error.

🙂 Expected behavior

The same result at every checker count.

The --singleThreaded behavior makes sense to me, but honestly any behavior that can be made consistent across checkers count would be fine with me.

With 1 or 2 checkers, or --singleThreaded, or on TS6, we get:

consumer.ts(3,14): error TS2322: Type '0' is not assignable to type 'keyof Props'.

Additional information about the issue

My agent's analysis:


Version --singleThreaded / --checkers 1 --checkers 2 --checkers 3 default (4) --checkers 8
6.0.3 (one checker) TS2322 n/a n/a n/a n/a
7.0.2 TS2322 no error no error no error no error
7.1.0-beta TS2322 TS2322 no error no error no error
main at 5e32f32 (Nov 16) TS2322 TS2322 no error no error no error
#65293 at 9a2e423 TS2322 TS2322 no error no error no error

Each configuration gives the same result on every run (10 of 10 for every cell with 7.0.2, main and #65293), so this comes from how the files are split across checkers, not from a race.

This is the same kind of bug as #64998, but the cause is different: #65293 at 9a2e423 fixes #64998 but not this. With one base interface instead of two, 6.0.3 gives string | number, and #65293 makes every checker count agree with it. With two bases, 6.0.3 gives "a" | "b", and #65293 still varies. In #65293's check-order harness, a compiler test of this case (below) gets the literal keys in the default order and string | number in reverse, isolated and typesfirst, and TS_CHECK_ORDER_FUZZ=40 changes the result for 30 of 40 seeds.

The order dependence underneath is already in 6.0.3: within one file, the same interface gets a different keyof depending only on whether it's checked before its keyof is needed. Multiple checkers turn that into a dependence on the checker count. Here are both orders in one file. 6.0.3 and 7 both give string | number for the first and "a" | "b" for the second, so only the second assignment errors: Playground (7.1.0-dev.20261030.1) · same file on 6.0.3

As far as I can tell, resolving Props's members evaluates its index signature, which computes keyof Props before the index signature exists and caches "a" | "b". Computed after the members are resolved, keyof Props is string | number.

The playground links above are on tsgo.sxzz.dev because it runs the command-line compiler built to wasm, so it honors "checkers". The official playground always shows the single-checker result here: its TS 7 mode goes through the project system, which doesn't use checkers.

Compiler test for #65293's check-order harness
// @strict: true
// @noEmit: true
// @checkOrder: default, reverse, isolated, typesfirst

// The index signature of Props refers to keyof Props. keyof Props is only the
// literal keys if it is computed while the members of Props are being resolved
// (checking props.ts first), and string | number otherwise.

// @filename: props.ts
interface BaseA { a?: string; }
interface BaseB { b?: number; c?: number[]; }
export interface Props extends BaseA, BaseB {
    [key: string]: Props[keyof Props];
}

// @filename: keys.ts
import {Props} from './props';
type PropKey = keyof Props;
const probe: never = null! as (number extends PropKey ? 'string | number' : 'literal keys only');

Activity

  1. jakebailey commented on Nov 17, 2026

    @jakebailey
    Member

    This is a one line fix in #65293 but I don't think it's fixable in main in the same way.

  2. blickly commented on Nov 17, 2026

    @blickly
    ContributorAuthor

    Great to hear. I can't wait for #65293

  3. jakebailey commented on Nov 17, 2026

    @jakebailey
    Member

    Unfortunately I wouldn't expect it for 7.1

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

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: check: Order DependenceErrors or types depend on the order of checker operations, e.g. LS / tsc discrepancies

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions