fix(ability): support classes with protected/private constructors in AnyClass type#1238
Open
hiro-nikaitou wants to merge 1 commit into
Open
fix(ability): support classes with protected/private constructors in AnyClass type#1238hiro-nikaitou wants to merge 1 commit into
hiro-nikaitou wants to merge 1 commit into
Conversation
…AnyClass type Change AnyClass from `new (...args: any[]) => T` to `abstract new (...args: any[]) => T` so that classes with protected or private constructors are correctly recognized as class types. This fixes InferSubjects and other type-level checks that previously failed for such classes. Closes stalniy#995 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Description
Changes
AnyClasstype fromnew (...args: any[]) => Ttoabstract new (...args: any[]) => Tso that classes with protected or private constructors are correctly recognized as class types.Background
Classes with protected/private constructors cannot be used with
newfrom outside, which meant they didn't match thenew (...args: any[]) => Tconstraint inAnyClass. This causedInferSubjectsand other type-level checks to silently fail for such classes.The
abstractmodifier on the construct signature makes TypeScript accept both concrete classes and classes that cannot be directly instantiated (protected/private constructors, abstract classes).Changes
types.ts:AnyClassusesabstract newinstead ofnewAbilityBuilder.ts: Added type assertion to concrete construct signature where runtime check guarantees instantiationRelated Issue
Closes #995
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com