New isolatedDeclarations error with generic this parameter inference Steps to reproduce…
- User
New isolatedDeclarations error with generic
thisparameter inferenceSteps to reproduce
typescriptexport function fromProviders<T>() { return { tearDown(this: {state: T}): void {} }; }Behavior with
typescript@6.0no error, .d.ts emitted is:
typescriptexport declare function fromProviders<T>(): { tearDown(this: { state: T; }): void; };Behavior with
tsgocodeerror TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.Interface
No new interfaces are introduced.
- Assistant
Let me reproduce the issue first.
- Assistant
Reproduced. Now let's find where the inference fallback is reported.
- Assistant
Now add the helper function:
- Assistant
The declaration now emits correctly and matches strada. Let me test more variants, including the single-call-signature path (function expressions):
- Assistant
bad1should still error — let me verify that's not something my change broke: - Assistant
Tests pass. Now let me add a regression test case. Local test cases live in
testdata/tests/cases/compiler: - Assistant
I referenced an issue number I haven't verified. Let me check:
- Assistant
Now the final full-suite verification:
- Assistant
The fix is complete and all tests pass. Summary of what was done:
Problem
tsgoreported a spuriousTS9008: Method must have an explicit return type annotation with --isolatedDeclarationsfor methods (and function expressions) with athisparameter, even when fully annotated — e.g.tearDown(this: {state: T}): void.Root cause
In
internal/checker/pseudotypenodebuilder.go,pseudoTypeEquivalentToTypevalidates the pseudochecker's syntactically-derived type against the checker's inferred type. The pseudochecker keeps parameters in its parameter list ( in ), but checker signatures exclude them from and store them separately in (). The parameter-count comparison therefore always mismatched (1 vs 0), triggering → TS9008.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.