Abstract Class

Getting an error saying
src/server/components/Holdable.ts:26:21 - error TS2345: Argument of type 'typeof Holdable' is not assignable to parameter of type 'Constructor<object>'.
Cannot assign an abstract constructor type to a non-abstract constructor type.
src/server/components/Holdable.ts:26:21 - error TS2345: Argument of type 'typeof Holdable' is not assignable to parameter of type 'Constructor<object>'.
Cannot assign an abstract constructor type to a non-abstract constructor type.
I'm new to abstraction so I'm not sure if the way I've set it up is causing this problem but I'm having trouble debugging. Looking for someone to help me understand this error and how I might fix it.
import { OnStart } from "@flamework/core";
import { Component, BaseComponent } from "@flamework/components";

interface Attributes {}

export interface HoldableInstance extends Model {
PrimaryPart: (Part | BasePart) & {
PromptAttachment: Attachment & {
ProximityPrompt: ProximityPrompt;
}
}
}

@Component()
/**
* Abstract class for holdable items
*/
export abstract class Holdable extends BaseComponent<Attributes, HoldableInstance> implements OnStart {
abstract debugTag: string

onStart() {
print(this.debugTag);
}
}
import { OnStart } from "@flamework/core";
import { Component, BaseComponent } from "@flamework/components";

interface Attributes {}

export interface HoldableInstance extends Model {
PrimaryPart: (Part | BasePart) & {
PromptAttachment: Attachment & {
ProximityPrompt: ProximityPrompt;
}
}
}

@Component()
/**
* Abstract class for holdable items
*/
export abstract class Holdable extends BaseComponent<Attributes, HoldableInstance> implements OnStart {
abstract debugTag: string

onStart() {
print(this.debugTag);
}
}
2 Replies
PoppingPopper
PoppingPopperOP3y ago
Starting to feel like I can't use the @Component decorator for abstract classes (I was hoping I could latch onto onStart's implementation in a child class to initialize some holdable functionality) Does this mean abstraction altogether is not optimal for usage in flamework? Or just the decorators? meh I guess it should work if I just pass the instance to my abstract methods. Thanks, can't wait to see this implemented in flamework!
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?