Skip to content

icetomcat/mixwith

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published