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 trace the isolated-declarations return-type inference and its tests, reproduce the generic
thiscase, then implement the narrowest fix and run the relevant test suite. I’ll first inspect the repository layout and search for TS9008 and inferred return-type handling. - Assistant
The repository is the Go TypeScript implementation, and the initial search did not hit because the relevant code is likely under
internal. I’ll locate the diagnostic definition and declaration-emitter logic, then identify existing conformance tests for isolated declarations. - Assistant
The reproduction confirms the emitter already produces the correct declaration, but the pseudo-type reuse check incorrectly reports an inference fallback (TS9008) for an object-literal method with a
thisparameter. I’ll preserve the existing fast path generally, but when the inferred return expression contains athisparameter, skip that pseudo-check’s fallback diagnostic and let the checker serialize the return type—the same path that already emits the correct result. - Assistant
The first adjustment showed the diagnostic originates inside the pseudo-equivalence routine itself, not only in the later predicate check. I’ve now disabled fallback reporting at that exact comparison for affected return expressions; reproduction succeeds with no diagnostics and the expected
.d.ts. I’ll clean up the comment placement and run focused Go tests plus a few edge-case compilations. - Assistant
Focused checker/declaration tests pass, the original case and nested/annotated variants compile without diagnostics, and emitted declarations preserve the generic
thisparameter. I’ll run the broader internal Go test suite and inspect the final diff before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.