Skip to content
TheChatArchiveThe Chat Archive
fable-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

    Let me first reproduce the issue:

  3. Assistant

    Reproduced. Now let's find where this diagnostic originates:

  4. Assistant

    Now let me look at how the checker's Signature stores the this parameter to compare against:

  5. Assistant

    Now implement the fix in pseudotypenodebuilder.go. First the method case:

  6. Assistant

    Now the single-call-signature case:

  7. Assistant

    Now add the helpers:

  8. Assistant

    No error and correct emit. Let me test edge cases:

  9. Assistant

    Output is correct with no errors. Accept the baselines:

  10. Assistant

    Now run the broader test suite to check for regressions:

  11. Assistant

    While that runs, let me also run the checker package tests:

  12. Assistant

    The full suite passed suspiciously fast — let me verify whether the submodule tests actually ran or were skipped:

  13. Assistant

    While that runs, review the final diff:

  14. Assistant

    All 12,797 submodule test cases pass with no baseline changes. Let me clean up leftover local baselines and run one final full verification:

  15. Assistant

    The fix is complete and verified.

    Root cause

    With --isolatedDeclarations, tsgo validates syntactically-inferrable types against the checker's types in pseudoTypeEquivalentToType (internal/checker/pseudotypenodebuilder.go). The pseudochecker's cloneParameters includes an explicit this parameter in its parameter list (it's a regular parameter node in the AST), but the checker's Signature.parameters excludes it — the checker stores it separately as Signature.thisParameter. The resulting parameter-count mismatch (0 != 1 for tearDown(this: {state: T}): void) triggered a spurious ReportInferenceFallback → TS9008, even though the emitted .d.ts (produced by the checker fallback path) was correct.

    Changes

    internal/checker/pseudotypenodebuilder.go:

    • Added splitThisPseudoParameter, which splits an explicit leading this parameter off a pseudo parameter list.
    • Added pseudoThisParameterMatchesSignature, which validates the this parameter's type against the checker signature's thisParameter.
    • Applied both in the two affected comparison sites: the PseudoObjectElementKindMethod case (object-literal methods) and the PseudoTypeKindSingleCallSignature case (function expressions), so positional parameters are compared without the this parameter, which is now checked separately.

    testdata/tests/cases/compiler/isolatedDeclarationsThisParameter.ts (+ accepted reference baselines): covers the original repro (generic T in the this type), this plus regular/optional parameters, this: void, and a function expression with a this parameter. All emit correct declarations with no errors, reusing the source annotations (the pseudo path, not the checker fallback).

    Verification

    • Original repro now compiles cleanly and emits the same .d.ts as strada.
    • Full test suite passes: all 12,797 submodule compiler tests + local tests, with no baseline changes beyond the new test.
    • go build / go vet clean.

    One pre-existing, unrelated behavior noted while testing: returning a named as const local still errors with TS9039 (reproduced on the base commit as well), consistent with the type needing to be nameable.

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