Typescript: multiple inheritance?

I have come across a scenario migrating to typescript and octane, where I am having difficulties figuring out the right way in javascript. Pretty much what I need is multiple inheritance as shown below:

project -- private project-------
               \public project    \
                                   \
song -- private song -------- Shareable           
          \_ public song 

So, essentially, I have “abstract” classes (project, song) which exist in two variations: public and private. For instance project would define ED properties and methods that are the same for private and public projects. Then the private and public project classes inherit from project and define additional properties. This all worked fine so far, but now I need to add a second parent class Shareable. The Shareable base class would add methods and ED properties that are required to make a project or song shareable. This would be useful to implement a generic component that allows to share a private entity, by defining the input to be of type Shareable.

Long story short, my issue here is that js is not supporting multiple inheritance and I don’t see a way how I can make this work with single inheritance.

As for the backend, private project is a dedicated endpoint that requires authentication. public project is a dedicated endpoint that does not require authentication. And the result of sharing a private project is a public project.

The problem here is not Ember-specific; as you note:

js is not supporting multiple inheritance and I don’t see a way how I can make this work with single inheritance

In general, I find that reaching for multiple inheritance is nearly always something I’m going to regret later. In cases where it’s tempting, I reach instead for one of:

  • plain-old functions: they work surprisingly well for a lot of cases where people tend to try to use inheritance
  • delegates: define an interface that a property has to fulfill, and then supply it either directly via the constructor or via Ember’s DI system (including services, which are basically just singleton delegates)

In the pattern you’re describing, a delegate seems like exactly what you need. You don’t actually need the things you’re to be properties on the class itself (from what you’ve written anyway), just in some way associated with it, and a delegate is perfect for that.

Sorry about the late reply. A few urgent things got in the way. I think my issue is that I (coming from the strictly typed java world) was completely unaware how one can apply composition with classes in the js world. I have read through pages like JavaScript Inheritance vs Composition and this actually seems to be a good idea.

However, all that I tried to compose my ED model, nothing so far seemed to be working. My model looks like this:

import { validator, buildValidations } from 'ember-cp-validations';
import LoadableModel from 'ember-data-storefront/mixins/loadable-model';
import Model from 'ember-data/model';

const Validations = buildValidations({
})

export default class ProjectModel extends Model.extend(Validations).extend(LoadableModel) {
  
  @sort('replies', ['sort'], function() {
    // sort logic
  }) sortedReplies
}

I just want to extract that sort function, so I can use it on multiple models and apply it via composition. However, even my basic composition attempts have failed on ED classes.