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
I'll investigate how
tsgohandlesisolatedDeclarationsfor methods with genericthisparameters and compare it to TypeScript 6.0 behavior. - Assistant
Reproducing the error locally to see where it's reported.
- Assistant
Implementing the fix: the checker stores
thisparameters separately from regular parameters, but the pseudochecker comparison wasn't accounting for that. - Assistant
The fix works. Running tests and generating baselines.
- Assistant
Fixed. The bug was in how
tsgocompared pseudochecker signatures against checker signatures when a method has an explicitthisparameter.Root cause
The checker stores
thisparameters separately from regular parameters (signature.thisParametervssignature.parameters). The pseudochecker keeps them together in the AST parameter list.When validating isolated declarations,
pseudoTypeEquivalentToTypecompared parameter counts directly:- Pseudochecker: 1 parameter (
this: {state: T}) - Checker: 0 regular parameters (
thisstored separately)
That mismatch triggered
ReportInferenceFallbackon the method, producing TS9008 even though the method already had an explicit: voidreturn type.Fix
In
internal/checker/pseudotypenodebuilder.go, parameter comparison now:- Splits out a leading
thisparameter viasplitPseudoParameters
- Pseudochecker: 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.