How do I make and use a super class (or a base class) with type-checking?

Hi,

Can anyone tell me how I can make a superclass with typechecking and how I use the superclass in subclasses? I’ve tried to make a super class but I don’t really know the use of it. Thanks!

I guess you’re supposed to use table intersection for that? Something like this maybe (I never tested it)

type Superclass<Subtype> = {
    Method1: (self: Superclass<Subtype>, param: any) -> any,
}

type Subclass<Subtype1, Subtype2> = Superclass<Subtype1> & {
    Method2: (self: Subclass<Subtype1, Subtype2>, param: any) -> any,
}
1 Like