Skip to content

sub-trait typings with multiple super-traits #7

@devlsh

Description

@devlsh

hey - loving playing around with the lib right now, really well designed!

i was having a small issue when playing with sub-traits inheriting multiple super-traits - namely that it only takes the first trait supplied to augment the base class typings. i.e. given this README example:

//  Define regular sub-trait Foo, inheriting from super-traits Bar and Qux.
const Foo = trait([ Bar, Qux ], (base) => class Foo extends base { ... })
//                ============

i'd expect base to give the correct typings for Bar and Qux, however that doesn't seem to be the case:

const Bar = trait((base) => {
  return class Bar extends base {
    dispose() {
      console.log('Bar.dispose()');
    }
  };
});

const Qux = trait((base) => {
  return class Qux extends base {
    create() {
      console.log('Qux.create()');
    }
  };
});

const Foo = trait([Bar, Qux], (base) => {
  return class Foo extends base {
    constructor() {
      super();

      this.dispose(); // typed correctly, since `base` is `typeof Bar`
      this.create(); // `any` type
    }
  };
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions