[Repo Assist] [TypeScript] Fix static class members not re-declaring class-level type parameters (fixes #3504)#4533
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…fixes #3504) Static methods in TypeScript cannot inherit class-level type parameters implicitly (unlike instance methods). When a static method uses a class type parameter in its signature, TypeScript requires it to be re-declared on the static method itself. Previously, getMemberArgsAndBody always excluded entGenParams from declaredTypeParams for all attached (class) members, both static and instance. Instance methods are correct because TypeScript can access class type params implicitly. But static methods must re-declare any class type params they use. The fix adds a check for Attached(isStatic = true): in that case, entGenParams is included in declaredTypeParams so the type params appear on the static method signature. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Fixes a TypeScript validity bug where static class members that use class-level type parameters produce TypeScript errors because the type parameters are not re-declared on the static method.
Closes #3504
Root Cause
In
getMemberArgsAndBody(Fable2Babel.fs), thedeclaredTypeParamslist controls which type parameters appear in the TypeScript method signature. For attached (class) members, the code previously excluded class-level type parameters (entGenParams) for all cases — both static and instance.This is correct for instance methods: TypeScript instance methods can access class type params implicitly. But static methods cannot — TypeScript requires them to explicitly re-declare any class type params they use in their signature.
Example (before):
Example (after):
The Fix
In
getMemberArgsAndBody, when computingdeclaredTypeParamsfor an attached member, check ifkind = Attached(isStatic = true). If so, includeentGenParams(the class-level type params) indeclaredTypeParamsalongside the method's own generic parameters.The change is minimal — ~5 lines changed in
getMemberArgsAndBody. No impact on JavaScript output (the typeParams path is TypeScript-only).