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 how
tsgohandlesisolatedDeclarationsfor methods with genericthisparameters — searching the codebase for the TS9008 error and related logic. - Assistant
Reproducing the issue locally, then tracing the pseudochecker logic.
- Assistant
Implementing the fix: the pseudochecker includes
thisin its parameter list, but the checker stores it separately on the signature. - Assistant
Adding the helper method referenced by the refactor:
- Assistant
Fix verified. Running related tests and checking for other edge cases:
- Assistant
Fixed a bug in isolated declarations validation for methods with generic
thisparameters.Root cause
When validating object literal types under
--isolatedDeclarations,pseudoTypeEquivalentToTypecompared pseudochecker parameters against checker signature parameters directly. The pseudochecker includes thethisparameter in its parameter list, but the checker stores it separately onsignature.thisParameter. For a method liketearDown(this: {state: T}): void {}, that produced a count mismatch (1 vs 0) and incorrectly reported TS9008.Fix
In
internal/checker/pseudotypenodebuilder.go, parameter comparison now accounts forthisparameters:signaturePseudoParameterCount— counts both regular andthisparametersgetSignatureParameterForPseudoParameter— maps pseudo parameters to the correct checker symbolpseudoParametersEquivalentToSignature— shared comparison logic used for object literal methods and single call signatures
Verification
The reproducer now emits the expected
.d.ts:export declare function fromProviders<T>(): { tearDown(this: { state: T; }): void; };Added a regression test at
testdata/tests/cases/compiler/isolatedDeclarationsGenericThisParameter.tswith corresponding baselines.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →