Skip to content

TS2719 assigning equivalent conditional mapped types returned by a method #1020

Closed as not planned

Description

@nperez0111

tsrs 7.1.0-beta.tsrs2, bundled with Vite+ 1.7.0.

repro.ts

type Schema = Record<string, { props: Record<string, unknown>; content: string }>;
type Spec<K extends string, P, C> = { name: K; props: P; content: C };

export class CustomSchema<S extends Schema> {
  public specs: {
    [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never;
  };

  constructor() {
    const { specs } = this.init();
    this.specs = specs; // TS2719
  }

  private init() {
    const specs = {} as {
      [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never;
    };
    return { specs };
  }
}

tsconfig.json

{"compilerOptions":{"strict":true,"noEmit":true,"target":"ESNext","module":"ESNext","types":[]},"include":["repro.ts"]}
pnpm add -D vite-plus@1.7.0
pnpm exec vp lint repro.ts --type-aware --type-check

Actual: TS2719 at this.specs = specs: the two identically printed mapped types are “unrelated.”

Expected: assignment succeeds, as it does with tsgolint 7.0.2004.

Activity

  1. oxc-captain commented on Nov 17, 2026

    @oxc-captain
    Contributor
    • Reproduced: No
    • Exploration: Yes — compared the reproduction against the pinned Microsoft TypeScript Go compiler and tsrs behaves identically.
    • Unit Test: No — the behavior matches the upstream reference, so this is not a tsrs-specific parity defect to add a regression test for.
    • Priority: P3: Narrow or low-impact issue. This matches the upstream reference compiler at the pinned 7.1.0-beta commit, and it only manifests in a specific pattern of generic class + conditional mapped types returned from a private method.

    I ran the minimal reproduction with both tsrs 7.1.0-beta.tsrs2 and a freshly built tsgo binary from the pinned commit 3e9236361fa9. Both produced the exact same TS2719 error, including the nested string & K is not assignable to K message. This means the Rust port is not diverging from its upstream target.

    I wasn't able to find a fix, but I identified where this is coming from. The diagnostic originates in the upstream TypeScript Go compiler at the pinned 7.1.0-beta commit. The fact that tsgolint 7.0.2004 accepts the code suggests a behavioral change was introduced between 7.0.2004 and 7.1.0-beta. If tsrs should accept this, the change needs to be ported from a later upstream TypeScript commit rather than fixed in tsrs-specific code.

    Full Triage Report

    Triage Report: Issue #1020

    Issue claim

    Assigning two equivalent conditional mapped types (returned by a private method) to each other incorrectly produces TS2719 in tsrs 7.1.0-beta.tsrs2. The reporter notes the assignment succeeds in tsgolint 7.0.2004.

    Minimal input

    Created at /tmp/triage-1020/repro:

    repro.ts:

    type Schema = Record<string, { props: Record<string, unknown>; content: string }>;
    type Spec<K extends string, P, C> = { name: K; props: P; content: C };
    
    export class CustomSchema<S extends Schema> {
      public specs: {
        [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never;
      };
    
      constructor() {
        const { specs } = this.init();
        this.specs = specs; // TS2719
      }
    
      private init() {
        const specs = {} as {
          [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never;
        };
        return { specs };
      }
    }

    tsconfig.json:

    {"compilerOptions":{"strict":true,"noEmit":true,"target":"ESNext","module":"ESNext","types":[]},"include":["repro.ts"]}

    Compiler revisions

    • tsrs: 7.1.0-beta.tsrs2, pinned microsoft/TypeScript@3e9236361fa97a9e6c685f4833ac457ae2d8c50a
    • TypeScript Go reference: built from triagebot/fix-1020/Cargo.toml commit 3e9236361fa97a9e6c685f4833ac457ae2d8c50a
    • Go tsc binary: /tmp/triage-1020/tsgo-tsc — reports Version 7.1.0-beta

    Commands run

    Build tsrs:

    cd /home/runner/work/tsrs/tsrs
    cargo build --profile dev --locked -p tsrs_cli -p tsrs_testrunner

    Build reference TypeScript Go compiler:

    cd /tmp/triage-1020/ts-ref/tsc
    GOTOOLCHAIN=auto GOWORK=off go build -o /tmp/triage-1020/tsgo-tsc ./cmd/tsc

    Run tsrs:

    cd /tmp/triage-1020/repro
    /home/runner/work/tsrs/tsrs/target/debug/tsrs -p tsconfig.json --pretty false

    Run TypeScript Go:

    cd /tmp/triage-1020/repro
    /tmp/triage-1020/tsgo-tsc -p tsconfig.json --pretty false

    Observed outputs

    tsrs

    repro.ts(11,5): error TS2719: Type '{ [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never; }' is not assignable to type '{ [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never; }'. Two different types with this name exist, but they are unrelated.
      Type 'K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never' is not assignable to type 'K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never'. Two different types with this name exist, but they are unrelated.
        Type 'Spec<K, S[K]["props"], S[K]["content"]>' is not assignable to type 'K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never'.
          Type 'Spec<K, S[K]["props"], S[K]["content"]>' is not assignable to type 'Spec<K, S[K]["props"], S[K]["content"]>'. Two different types with this name exist, but they are unrelated.
            Type 'string & K' is not assignable to type 'K'.
              'string & K' is only assignable to the non-distributed 'K', but 'K' has been distributed here.
    EXIT: 2
    

    TypeScript Go reference

    repro.ts(11,5): error TS2719: Type '{ [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never; }' is not assignable to type '{ [K in keyof S]: K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never; }'. Two different types with this name exist, but they are unrelated.
      Type 'K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never' is not assignable to type 'K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never'. Two different types with this name exist, but they are unrelated.
        Type 'Spec<K, S[K]["props"], S[K]["content"]>' is not assignable to type 'K extends string ? Spec<K, S[K]["props"], S[K]["content"]> : never'.
          Type 'Spec<K, S[K]["props"], S[K]["content"]>' is not assignable to type 'Spec<K, S[K]["props"], S[K]["content"]>'. Two different types with this name exist, but they are unrelated.
            Type 'string & K' is not assignable to type 'K'.
              'string & K' is only assignable to the non-distributed 'K', but 'K' has been distributed here.
    EXIT: 2
    

    Result

    NOT REPRODUCED as a tsrs parity defect.

    The checked-out tsrs produces exactly the same TS2719 diagnostic as the pinned Microsoft TypeScript Go compiler (3e9236361fa9). The reporter's observation that tsgolint 7.0.2004 accepts the code indicates an upstream change between that build and the pinned 7.1.0-beta commit, not a divergence in the Rust port.

    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. nperez0111 commented on Nov 17, 2026

    @nperez0111
    Author

    Correction: my comparison used different compiler versions. Latest tsgolint 7.0.2007 targets TypeScript 7.0.2, while tsrs 7.1.0-beta.tsrs2 targets 7.1.0-beta. Upgrading tsgolint still leaves the same two TS2719 differences in our repo, with all ten lint warnings identical, but that is not a version-matched comparison. The matched-revision test in the triage above reproduces TS2719 in Go too, so this does not establish a tsrs-specific defect. Closing; thanks for checking, and sorry for the misleading attribution.

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