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-declaration method inference path, add a focused regression test, implement the fix, and run the narrow relevant test suite.
- Assistant
rgisn’t installed in this checkout, so I’m using the repository’s available search tools and keeping the investigation scoped to declaration diagnostics and their tests. - Assistant
The failure is in the syntactic type model for object-literal methods: it preserves ordinary parameters but drops an explicit
thisparameter. That makes the syntactic model disagree with the checker model and incorrectly triggers the inference-fallback diagnostic, even though the method already has: void. I’m adding coverage around both generic and non-generic explicitthistypes before changing that model. - Assistant
The focused test now emits the expected
.d.tswith the explicitthisparameter and produces no isolated-declaration errors. I also covered function expressions because they use the same signature comparison and had the same false positive. Next I’m checking nearby declaration cases for regressions, then I’ll run the repository-required build/test/lint/format checks. - Assistant
The checkout doesn’t have Node/npm tooling (
npxis unavailable), so the repository’s baseline-accept/build/lint wrappers can’t run here. I’ll add the generated golden files withapply_patch, run the equivalent Go tests and build directly, and report the unavailable wrapper checks explicitly. - Assistant
The regression and the nearby object-literal isolated-declaration suite both pass. The golden output exactly preserves
this: { state: T }and removes TS9008/TS9007. I’m on the final direct Go build and full test pass now; the Node-based wrappers remain unavailable in this environment. - Assistant
The unconstrained full Go test fan-out hit the container’s process/thread limit (
resource temporarily unavailable/newosproc), not a code failure. The changed checker package and many others passed before that. I’m rerunning the full suite with Go package concurrency capped to fit the environment.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.