New isolatedDeclarations error with generic this parameter inference Steps to reproduce…
- User
New isolatedDeclarations error with generic
thisparameter inferenceSteps to reproduce
typescriptexport function fromProviders<T>() { return { tearDown(this: {state: T}): void {} }; }Behavior with
typescript@6.0no error, .d.ts emitted is:
typescriptexport declare function fromProviders<T>(): { tearDown(this: { state: T; }): void; };Behavior with
tsgocodeerror TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.Interface
No new interfaces are introduced.
- Assistant
Investigating the isolatedDeclarations check for methods with generic
thisparameters — searching the codebase for where TS9008 is emitted. - Assistant
Implementing the fix:
cloneParametersincludesthisparameters, but signature comparison usestargetSig.parameters, which excludes them — causing a false parameter-count mismatch. - Assistant
Fixed a false positive
TS9008in isolated declarations when a method has an explicit genericthisparameter.Root cause
When comparing pseudo-types against checker signatures during isolated declaration emit, parameter counts were compared directly. The pseudochecker includes explicit
thisparameters in its parameter list (from the AST), but checker signatures storethisseparately insignature.thisParameter, not insignature.parameters.For
tearDown(this: {state: T}): void {}:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.