New isolatedDeclarations error with generic this parameter inference Steps to reproduce…
- User
New isolatedDeclarations error with generic
thisparameter inferenceSteps to reproduce
export function fromProviders<T>() { return { tearDown(this: {state: T}): void {} }; }Behavior with
typescript@6.0no error, .d.ts emitted is:
export declare function fromProviders<T>(): { tearDown(this: { state: T; }): void; };Behavior with
tsgoerror TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.Interface
No new interfaces are introduced.
- Assistant
Investigating the isolatedDeclarations handling for generic
thisparameters in tsgo. - Assistant
Reproducing the error and tracing where inference fallback is triggered.
- Assistant
Implementing the fix: pseudo-parameter comparison should account for
thisparameters stored separately on signatures. - Assistant
Fixed a bug in isolatedDeclarations pseudo-type validation for methods with explicit
thisparameters.Root cause
When validating object-literal method types under
--isolatedDeclarations, tsgo compared pseudo-checker parameters againstsignature.parameters. In the real checker, athisparameter is stored separately insignature.thisParameter, not inparameters.For this code:
tearDown(this: {state: T}): void {}- Pseudo-checker: 1 parameter (
this) - Checker signature: 0 parameters + 1
thisParameter
That mismatch triggered
ReportInferenceFallbackon the method, which surfaced as TS9008 even though the return type (void) was explicit. - Pseudo-checker: 1 parameter (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.