Skip to content
TheChatArchiveThe Chat Archive
composer-2.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

New isolatedDeclarations error with generic this parameter inference Steps to reproduce…

  1. User

    New isolatedDeclarations error with generic this parameter inference

    Steps to reproduce

    export function fromProviders<T>() {
      return {
        tearDown(this: {state: T}): void {}
      };
    }
    

    Behavior with typescript@6.0

    no error, .d.ts emitted is:

    export declare function fromProviders<T>(): {
        tearDown(this: {
            state: T;
        }): void;
    };
    

    link

    Behavior with tsgo

    error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.
    

    link

    Interface

    No new interfaces are introduced.

  2. Assistant

    Investigating how tsgo handles isolatedDeclarations for methods with generic this parameters — searching the codebase for the TS9008 error and related logic.

  3. Assistant

    Reproducing the issue locally, then tracing the pseudochecker logic.

  4. Assistant

    Implementing the fix: the pseudochecker includes this in its parameter list, but the checker stores it separately on the signature.

  5. Assistant

    Adding the helper method referenced by the refactor:

  6. Assistant

    Fix verified. Running related tests and checking for other edge cases:

  7. Assistant

    Fixed a bug in isolated declarations validation for methods with generic this parameters.

    Root cause

    When validating object literal types under --isolatedDeclarations, pseudoTypeEquivalentToType compared pseudochecker parameters against checker signature parameters directly. The pseudochecker includes the this parameter in its parameter list, but the checker stores it separately on signature.thisParameter. For a method like tearDown(this: {state: T}): void {}, that produced a count mismatch (1 vs 0) and incorrectly reported TS9008.

    Fix

    In internal/checker/pseudotypenodebuilder.go, parameter comparison now accounts for this parameters:

    • signaturePseudoParameterCount — counts both regular and this parameters
    • getSignatureParameterForPseudoParameter — maps pseudo parameters to the correct checker symbol
    • pseudoParametersEquivalentToSignature — shared comparison logic used for object literal methods and single call signatures

    Verification

    The reproducer now emits the expected .d.ts:

    export declare function fromProviders<T>(): {
        tearDown(this: {
            state: T;
        }): void;
    };
    

    Added a regression test at testdata/tests/cases/compiler/isolatedDeclarationsGenericThisParameter.ts with corresponding baselines.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.