/mixwith

Primary LanguageTypeScriptMIT LicenseMIT

TypeScript Mixin library

Examples

Basic usage

class Base {}

const NameMixin = Mixin(<T extends Constructor>(superclass: T) => class extends superclass { name = "Node" })

const IdMixin = Mixin(<T extends Constructor>(superclass: T) => class extends superclass { id = nanoid() })

class MyClass extends mix(Base).with(NameMixin, IdMixin) {}

console.log(new MyClass()) // MyClass { name: 'Node', id: '2FHGySBlhFAMRwkiMiU9D' }

Instance of

if (myClass instanceof SomeMixin) doSomething()

Types

type NameMixinType = MixinType<typeof NameMixin>
type IdMixinType = MixinType<typeof IdMixin>

type UserType = NameMixinType & IdMixinType

class User extends mix(Base).with(NameMixin, IdMixin) implements UserType {}

Development

Install the dependencies

yarn install

Start the app in development mode

yarn start

Run tests

yarn test

Run tests in watch mode

yarn test:watch

Generate bundles and typings, create docs

yarn build