Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-mixer

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-mixer

A very small TypeScript library that provides tolerable Mixin functionality.

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
615K
decreased by-20.38%
Maintainers
1
Weekly downloads
 
Created

What is ts-mixer?

The ts-mixer package is a TypeScript library that provides utilities for creating mixins and multiple inheritance in TypeScript. It allows developers to combine multiple classes into one, enabling more flexible and reusable code structures.

What are ts-mixer's main functionalities?

Basic Mixin

This feature allows you to create a new class that combines the methods and properties of multiple classes. In this example, class C inherits methods from both class A and class B.

const { Mixin } = require('ts-mixer');

class A {
  methodA() {
    console.log('Method A');
  }
}

class B {
  methodB() {
    console.log('Method B');
  }
}

class C extends Mixin(A, B) {}

const c = new C();
c.methodA(); // Method A
c.methodB(); // Method B

Advanced Mixin with Constructor

This feature demonstrates how to handle constructors when mixing classes. The new class C can initialize properties from both class A and class B.

const { Mixin } = require('ts-mixer');

class A {
  constructor(public name: string) {}
  methodA() {
    console.log(`Method A: ${this.name}`);
  }
}

class B {
  constructor(public age: number) {}
  methodB() {
    console.log(`Method B: ${this.age}`);
  }
}

class C extends Mixin(A, B) {
  constructor(name: string, age: number) {
    super(name, age);
  }
}

const c = new C('John', 30);
c.methodA(); // Method A: John
c.methodB(); // Method B: 30

Mixin with Interfaces

This feature shows how to use mixins with interfaces. Class C implements both IA and IB interfaces and inherits methods from class A and class B.

const { Mixin } = require('ts-mixer');

interface IA {
  methodA(): void;
}

interface IB {
  methodB(): void;
}

class A implements IA {
  methodA() {
    console.log('Method A');
  }
}

class B implements IB {
  methodB() {
    console.log('Method B');
  }
}

class C extends Mixin(A, B) implements IA, IB {}

const c = new C();
c.methodA(); // Method A
c.methodB(); // Method B

Other packages similar to ts-mixer

Keywords

FAQs

Package last updated on 16 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc