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
I’ll trace the isolated-declarations return-type inference path for object-literal methods, patch the generic
thiscase, and run the focused compiler tests plus nearby coverage. - Assistant
rgisn’t installed in this checkout, so I’m using targetedfind/grepsearches instead. The worktree is clean, and there are no repository-specificAGENTS.mdinstructions. - Assistant
The failure is in the syntactic pseudo-checker’s signature comparison: it treats an explicit
thisparameter as an ordinary positional parameter, while the semantic checker stores it separately. That makes the method signature look incompatible and triggers TS9008. I’m narrowing the patch to parameter cloning/comparison so emittedthistypes are still preserved. - Assistant
The checker/compiler unit suites compile and pass with the signature fix. I’ve added a focused regression case matching the report and am generating/verifying its declaration baseline now.
- Assistant
The regression now emits the expected declaration with no isolated-declarations diagnostic. The key correction handles
thisseparately in both object-method and function-signature comparisons, matching the checker’s representation while retaining it in.d.tsoutput. I’m running the complete local compiler baseline suite and final package checks.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.