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
Let me reproduce the issue first.
- Assistant
Reproduced. Now let's find where the error originates.
- Assistant
Now let me implement the fix in
pseudotypenodebuilder.go: - Assistant
Now add the helper function after
pseudoTypeEquivalentToType: - Assistant
All emit correctly. Let me verify against strada's tsc if available, then run the test suites:
- Assistant
The baseline output is correct. Let me accept the baselines:
- Assistant
No node in this environment — I'll copy the local baselines to reference manually (the equivalent of
baseline-accept): - Assistant
Now run the broader test suites to check for regressions:
- Assistant
That was suspiciously fast — the submodule tests may be skipped. Let me check:
- Assistant
All submodule baselines unchanged. Let me verify formatting and run
go veton the changed package: - Assistant
The fix is complete. Here's a summary:
Root cause
Under
--isolatedDeclarations, tsgo validates the pseudochecker's syntactically-derived types against the real checker's types before reusing them for declaration emit (pseudoTypeEquivalentToTypeininternal/checker/pseudotypenodebuilder.go). The pseudochecker includes an explicitthisparameter in itsParameterslist (it's a regular entry in the sourceParameterList), but the checker'sSignaturestores it separately inthisParameter— never inSignature.parameters. The parameter-count comparison therefore misaligned (1 pseudo param vs 0 checker params), the equivalence check failed, and a spurious inference-fallback was reported as TS9008.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.