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 inspect the repository structure and locate the isolated-declarations diagnostics and method return-type inference paths. Then I’ll reproduce the reported case with the project’s existing test/build tooling before making a focused fix.
- Assistant
rgis unavailable in the environment, so I’ll usegrep/find. I’m looking for the diagnostic definition and the code that determines whether object-literal methods can have their signatures emitted under isolated declarations. - Assistant
The error originates in declaration transformation rather than semantic checking. I’ll inspect signature transformation and the upstream TypeScript submodule implementation for parity, since the expected TypeScript 6 behavior likely already identifies the precise inference rule.
- Assistant
I found that inferred return types are requested through
CreateReturnTypeOfSignatureDeclaration, with isolated-declaration errors supplied by a tracker callback. I’ll read both the method transform and the callback’s complete logic to determine why an explicitly typedthisparameter is incorrectly treated as inference-dependent. - Assistant
The declaration transformer reports TS9008 only when the checker/node-builder calls
ReportInferenceFallback. The important question is why serialization of this method’s inferredvoidreturn reaches a fallback. I’ll inspect the node-builder’s return-type inference andthis-parameter handling, and search repository history/remotes for an existing parity fix. - Assistant
The fallback is produced while comparing the syntactically inferable “pseudo type” against the checker’s actual type. I’ll inspect the signature pseudo-type conversion around the reported lines, then build the CLI and run the exact repro to confirm both the diagnostic and emitted declaration locally.
- Assistant
The likely mismatch is now clear: checker signatures store
thisseparately from ordinary parameters, while the pseudo-signature comparison checks onlytargetSig.parameters. If the pseudo checker includes the explicitthisparameter in itsParametersslice, the lengths differ and TS9008 is reported on the method. I’ll verify that representation and test variants (generic/non-genericthis, additional ordinary parameters) to ensure the fix is general rather than case-specific. - Assistant
I’ll now inspect exactly how object methods are cloned into pseudo signatures and whether their
thisparameter is retained. I’ll also buildtsgodirectly (the Go CLI can be built without the full npm pipeline) and run the repro plus controls. - Assistant
Inspection confirms the representation mismatch:
cloneParametersincludes every AST parameter, includingthis, but checkerSignature.parametersexcludesthisand stores it inSignature.thisParameter. The correct fix is to compare the pseudothisparameter againsttargetSig.thisParameter, then compare remaining pseudo parameters against ordinary checker parameters; this also preservesthisin emitted function types. Before editing, I’ll establish the failing output with a local Go cache and compare TypeScript’s output for the same controls. - Assistant
The first build attempt was blocked only because this sandbox has no
HOMEor default Go build cache. I’ll rerun with explicit temporaryGOCACHE,GOPATH, and module-cache paths; TypeScript’s npm binary is not installed, but the issue’s expected output and the repository baselines are sufficient for parity. - Assistant
The local repro confirms the bug affects any explicitly typed
thisparameter, including methods with additional ordinary parameters; all declarations are emitted correctly but each gets a spurious TS9008. I’ll update the pseudo/checker signature equivalence logic to account for the separately storedthissymbol while retaining existing parameter-level diagnostics for actual type/optionality mismatches. - Assistant
The fix now explicitly validates and compares the pseudo
thisparameter, offsets ordinary parameter comparison by one, and rejects inconsistent signatures defensively. I’ll rebuild and rerun the exact repro plus controls, then inspect declarations and diagnostics. - Assistant
The signature-level adjustment compiles but does not remove the diagnostic, so the failing path is earlier: object-literal methods use
PseudoObjectMethod, notPseudoTypeSingleCallSignature. I’ll trace the object-method equivalence branch and apply the samethis-parameter representation correction at the actual comparison point; I’ll avoid retaining unrelated code if that branch is unreachable for this case. - Assistant
The actual failing comparison indeed checks
len(targetSig.parameters)against all pseudo method parameters and therefore countsthisincorrectly. The signature-level fix is still needed for function expressions with explicitthis, which use the other branch. I’ll make object-method comparison mirror the corrected logic and then test both object methods and function-expression edge cases. - Assistant
The exact repro and non-generic/additional-parameter controls now pass with status 0 and emit the expected
thisparameter types. I’ll exercise adjacent cases in a temporary file: function expressions (the second corrected branch), generic method-local type parameters, and invalid inference cases that must continue reporting isolated-declaration errors. Then I’ll run focused package tests. - Assistant
Adjacent testing shows both corrected branches work: function expressions emit
(this: …) => void, and methods with their own generic type parameters emit correctly. Cases lacking an explicit return type still report TS9008, so the fix does not broadly suppress inference diagnostics. Focused checker/pseudochecker/declaration-transformer tests pass.I’ll now review accessor handling and the final diff for unintended scope, then run broader relevant tests or the repository’s compiler baseline test target if discoverable.
- Assistant
The final diff is confined to pseudo-type equivalence and is formatting-clean. Accessors have separate pseudo representations and do not use the affected all-parameters-vs-ordinary-parameters comparison, so no accessor change is needed. I’ll run the full Go test suite to catch any broader checker/node-builder regressions, then inspect status for accidental files.
- Assistant
The full
go test ./...suite passes. I’ll perform a final repository status/diff check to ensure only the intended source file changed and no temporary repro artifacts entered the repository. After that I’ll submit with the requested checklist assessment. - Assistant
Final assessment:
- Reproduced the reported error: Yes. The original example produced TS9008 with the pre-fix
tsgo, while still emitting the shown declaration. - Confirmed the fix resolves it: Yes. The exact example now exits successfully with no diagnostic and emits
tearDown(this: { state: T }): void. - Considered edge cases: Yes. I verified non-generic
this, additional ordinary parameters, method-local generics, and function expressions. I also confirmed methods without explicit return annotations still report TS9008. The implementation handles checker signatures’ separatethisParameterrepresentation in both object-method and single-call-signature comparisons. - Ran affected existing tests: Yes. Focused checker/pseudochecker/declaration-transformer tests passed, followed by the complete
go test ./...suite.git diff --checkalso passes. - Repository cleanliness: Only
internal/checker/pseudotypenodebuilder.gois modified; temporary repros were kept under/tmp.
I’m satisfied that the issue is resolved and will submit the change.
- Reproduced the reported error: Yes. The original example produced TS9008 with the pre-fix
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.