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 inference path for object-literal methods with explicit
thisand return annotations, then patch it and run the focused compiler tests. - Assistant
rgisn’t installed in this checkout, so I’m using targetedgrep/file discovery instead. First I’m locating the diagnostic and the declaration serializer checks that decide whether a method’s annotation is reusable. - Assistant
The failure is in syntactic type validation: the pseudo-signature counts the explicit
thisparameter, while the checker stores it separately from ordinary parameters. That makes an otherwise reusable method signature appear to have the wrong arity. I’m adjusting the comparison to treatthisseparately and adding coverage for both object methods and function expressions. - Assistant
The focused compiler run now has no isolated-declaration diagnostics and emits the expected generic
thistypes. The test harness is failing only because this is a new test and its reference baselines do not exist yet; I’m reviewing those generated outputs, then I’ll add the approved baselines and rerun. - Assistant
The new regression test passes and its
.d.tsexactly matches the expected output. I’ve also kept the comparison behavior unchanged for methods without explicitthis; the new logic only offsets and validatesthiswhen it is actually present. I’m running the checker package and the existing local isolated-declarations tests for regression coverage.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.