Skip to content

fix(ability): support classes with protected/private constructors in AnyClass type#1238

Open
hiro-nikaitou wants to merge 1 commit into
stalniy:masterfrom
hiro-nikaitou:fix/protected-constructor-types
Open

fix(ability): support classes with protected/private constructors in AnyClass type#1238
hiro-nikaitou wants to merge 1 commit into
stalniy:masterfrom
hiro-nikaitou:fix/protected-constructor-types

Conversation

@hiro-nikaitou

Copy link
Copy Markdown

Description

Changes AnyClass type 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.

Background

Classes with protected/private constructors cannot be used with new from outside, which meant they didn't match the new (...args: any[]) => T constraint in AnyClass. This caused InferSubjects and other type-level checks to silently fail for such classes.

The abstract modifier 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: AnyClass uses abstract new instead of new
  • AbilityBuilder.ts: Added type assertion to concrete construct signature where runtime check guarantees instantiation

Related Issue

Closes #995

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing type-checking in classes with protected constructor

1 participant