ISSUE DESCRIPTION New isolatedDeclarations error with generic this parameter inference…
- User
ISSUE DESCRIPTION
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.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I’ll first locate the isolated-declarations implementation and relevant tests, then reproduce the reported generic
thiscase through the project’s normal test or CLI path. I’ll identify why return-type inference rejects the method, implement the narrowest fix, add no repository tests per instructions, and run targeted plus broader validation. - Assistant
The reproduction confirms TS9008. The failure is in the pseudo-type equivalence used to reuse the object-literal syntax: pseudo-checking stores an explicit
thisparameter in the method’s parameter list, while checker signatures store it separately (thisParameter) and exclude it fromparameters. The equivalence code therefore reports a mismatch before the checker can serialize the valid inferred return type. I’ll make that comparison account for the separatethisParameter, preserving the parameter for emitted declarations while comparing ordinary parameters at the correct offset. - Assistant
The fix now emits the exact expected declaration, including
tearDown(this: { state: T }): void, and a second temporary case verifies ordinary parameters remain aligned both with and withoutthis. Targeted checker/declaration transformer tests pass. I’ll do one broader package test/build-oriented validation, inspect status, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.