{"id":15246,"library":"ts-mixer","title":"TypeScript Mixin Utility","description":"ts-mixer is a lightweight TypeScript library designed to provide robust mixin functionality, addressing common pitfalls found in other mixin implementations. It enables developers to compose classes through a multiple-inheritance-like mechanism, supporting complex scenarios such as mixing classes that extend other classes, abstract classes (TypeScript >= 4.2), and generic classes (with specific caveats). The current stable version is 6.0.4. The project appears to follow a release cadence driven by feature development and bug fixes, as indicated by its conventional commits usage. Key differentiators include its ability to support static, protected, and private properties, as well as a more resilient approach to constructor complexities and decorator usage compared to simple function-returning-class solutions. It offers different mixing strategies, including ES6 proxies and hard copies, providing flexibility for various use cases.","status":"active","version":"6.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/tannerntannern/ts-mixer","tags":["javascript","typescript","mixin","mixins","multiple inheritance","mixin classes"],"install":[{"cmd":"npm install ts-mixer","lang":"bash","label":"npm"},{"cmd":"yarn add ts-mixer","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-mixer","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary export for combining classes. Use named import for ESM. CommonJS environments should use `require` for interoperability, though the library is primarily designed for modern TypeScript/ESM.","wrong":"const Mixin = require('ts-mixer').Mixin;","symbol":"Mixin","correct":"import { Mixin } from 'ts-mixer';"},{"note":"Used specifically for mixing generic classes and leverages declaration merging. It's a named export, not a default.","wrong":"import mix from 'ts-mixer';","symbol":"mix","correct":"import { mix } from 'ts-mixer';"},{"note":"Replacement for `instanceof` checks with ts-mixer mixins. Requires ES6 `Map` or a polyfill.","wrong":"someInstance instanceof SomeMixin;","symbol":"hasMixin","correct":"import { hasMixin } from 'ts-mixer';"}],"quickstart":{"code":"import { Mixin } from 'ts-mixer';\n\nclass Foo {\n    protected makeFoo() {\n        return 'foo';\n    }\n}\n\nclass Bar {\n    protected makeBar() {\n        return 'bar';\n    }\n}\n\nclass FooBar extends Mixin(Foo, Bar) {\n    public makeFooBar() {\n        return this.makeFoo() + this.makeBar();\n    }\n}\n\nconst fooBar = new FooBar();\n\nconsole.log(fooBar.makeFooBar());","lang":"typescript","description":"Demonstrates basic class mixing with `ts-mixer` to combine functionalities from multiple base classes into a new derived class."},"warnings":[{"fix":"Use `hasMixin(instance, MixinClass)` instead of `instance instanceof MixinClass`.","message":"Direct `instanceof` checks will not work correctly with classes mixed using `ts-mixer`. The library provides a `hasMixin` function as a replacement.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Refer to the 'Mixing Generic Classes' section in the documentation for the correct `mix` function usage pattern.","message":"When mixing generic classes, a more cumbersome notation using the `mix` function and TypeScript's declaration merging is required due to TypeScript limitations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consult the 'Mixing with Decorators' section in the `ts-mixer` documentation for the correct usage pattern.","message":"Applying decorators to mixed classes also requires a specific, more verbose notation. Standard decorator application might not work as expected.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review the 'Dealing with Constructors' section in the documentation for workarounds and understanding potential impacts on your constructor logic.","message":"ES6 constructors cannot be called without `new`, which prevents `ts-mixer` from reliably passing the proper `this` context to base class constructors. This can affect how constructor logic behaves.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure `Map` is available in your runtime environment, either natively (ES6+) or through a polyfill.","message":"Certain features like `@decorator` and `hasMixin` rely on ES6 `Map`. If targeting environments older than ES6, you must provide a polyfill for `Map`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use the `mix` function provided by `ts-mixer` in conjunction with TypeScript's declaration merging to properly handle generic class mixing.","cause":"Attempting to mix generic classes using the standard `Mixin` function or without proper declaration merging.","error":"Base class expressions cannot reference class type parameters."},{"fix":"Replace `instanceof` checks with `ts-mixer`'s `hasMixin(instance, MixinClass)` utility function.","cause":"Trying to use `instanceof` with a class that was created using `ts-mixer`, which modifies the prototype chain in a way incompatible with native `instanceof`.","error":"TypeError: Right-hand side of 'instanceof' is not an object"}],"ecosystem":"npm"}