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.Interface
No new interfaces are introduced.
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
Build succeeded. Now let's run it on the repro file with isolatedDeclarations.
Assistant
Now let's implement the fix in pseudotypenodebuilder.go for both comparison sites.
Assistant
Good,
astis already imported. Let's add a helper function and update both comparison blocks.Assistant
Now let's add a helper function right before this function.
Assistant
Now let's update the two comparison sites to use these helpers.
Assistant
Now the second site,
PseudoTypeKindSingleCallSignature.Assistant
Now let's build and test.
Assistant
Build succeeded. Now let's rebuild tsgo and re-test the repro.
Assistant
The fix works and matches the expected output from the issue. Let's test some additional edge cases.
Assistant
All edge cases work correctly - additional parameters after
this, no-this case, function expressions withthis, arrow-contextthisin const declarations, and type predicates withthisparameter. Let's also test a mismatch scenario to ensure the fallback still triggers correctly when it should (e.g., wrongthistype causing legitimate error elsewhere), and run the existing test suite for the checker/declarations packages.Assistant
All these local isolatedDeclarations tests pass. Let's now run the submodule tests filtered to isolatedDeclarations to check the larger corpus (if the submodule is available).
Assistant
All tests pass. Let's view the full diff before finalizing.
Assistant
This looks clean and minimal. Let's do one more sanity check test to verify a mismatch (e.g., wrong
thistype doesn't type check, so the annotation is required and error appropriately triggers elsewhere) and also test with no isolatedDeclarations flag to ensure normal declaration emit still works fine.Assistant
Everything works as expected. Let's clean up temporary files.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.