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 methods with generic
thisparameters — searching the codebase for the TS9008 error path. - Assistant
Implementing a fix: pseudo-parameter comparison wasn't accounting for the checker's separate
thisParameterfield. - Assistant
The bug was in how
pseudoTypeEquivalentToTypecompared method/function signature parameters during isolated declarations emit.Root cause
The pseudochecker includes explicit
thisparameters in its parameter list (from the AST viacloneParameters). The checker storesthisseparately onSignature.thisParameter, not inSignature.parameters.For your example:
tearDown(this: {state: T}): void {}- Pseudo type: 1 parameter (
this) - Checker signature: 0 parameters in
parameters, 1 inthisParameter
The comparison
len(targetSig.parameters) != len(d.Parameters)failed (0 != 1), which triggeredReportInferenceFallbackand produced TS9008 even though the method already had an explicit: voidreturn type.Fix
- Pseudo type: 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.