Effect CommunityEC
Effect Community16mo ago
1 reply
Aldwin

Handling Abstract Properties in Extended Classes Using Class API

Using the Class API, how do you folks deal with Base.extend swallowing abstract properties?

abstract class Human extends S.Class<Human>('Human')({ name: S.String }) {
  abstract title: string;
  get fullname(){ return `${this.title} ${this.name}` }
}

class Doctor extends Human.extend<Doctor>('Doctor')({ specialty: S.String }) {
  // title = "Dr."
}

new Doctor({name: 'Phil', specialty: 'Psychology'}).fullname // "undefined Phil"


In the above example, I've commented out the title implementation in the Doctor class, but TypeScript doesn't care. It seems that Human.extend() returns a class that pretends to implement title, but really doesn't.
Was this page helpful?