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 diagnostic path for object-literal methods with explicit
thisparameters, patch the inference check, and run the focused compiler tests plus nearby coverage. - Assistant
The failure is in the syntactic type comparison: it counts the explicit
thisparameter as an ordinary argument, while the checker storesthisseparately. That false arity mismatch triggers TS9008 even though the return type is explicit. I’m adjusting the pseudo-signature parameter model and adding a regression case that verifies the emittedthis: { state: T }type. - Assistant
The checker and declaration-transformer packages compile and pass their Go tests. The JavaScript-based baseline runner isn’t available in this environment, so I’m also validating the exact source through the locally built
tsgobinary and inspecting its declaration output. - Assistant
The exact compiler run now succeeds and emits the expected generic declaration, including the explicit
thistype. The new compiler baseline test also passes; I’m doing the final diff and hygiene check now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.