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 first reproduce the issue:
- Assistant
Reproduced. Now let's find where the diagnostic is created:
- Assistant
Now add the helper function after
pseudoTypeEquivalentToType: - Assistant
All cases now emit correctly with no errors, matching TypeScript 6.0's output. Now run the relevant test suites:
- Assistant
The failures are just missing baselines for the new test. Let me accept them:
- Assistant
The output is correct. Accept the baselines:
- Assistant
Now run the full test suite to check for regressions:
- Assistant
All tests pass with no changes to existing baselines. Let me also run the broader package tests and
vet: - Assistant
The sandbox hit process limits with full parallelism. Retry with limited parallelism:
- Assistant
All tests pass. Final review of the change:
- Assistant
The fix is complete. Let me clean up and do a final verification of the original issue repro:
- Assistant
The fix is complete. The original repro now compiles without error and emits the exact
.d.tsthat TypeScript 6.0 produces.Summary
Root cause: In the isolatedDeclarations emit path, the pseudochecker clones the full syntactic parameter list of methods and function expressions — which includes a
thisparameter — while the checker'sSignaturestores thethisparameter separately inthisParameter, excluded fromSignature.parameters. The equivalence check inpseudoTypeEquivalentToTypecompared the raw lengths of the two lists, so any signature with an explicitthisparameter always failed validation and reported a spurious inference fallback (TS9008 for methods, TS9007 for function expressions) — even though the fallback serialization then emitted a perfectly correct declaration.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.