Skip to content

Commit

Permalink
fix: allow abstract constructor signatures for hasMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerntannern committed Feb 8, 2023
2 parents a953406 + 5b7722b commit 8964b59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mixin-tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getMixinsForClass = (clazz: Class) =>
export const registerMixins = (mixedClass: any, constituents: Function[]) =>
mixins.set(mixedClass, constituents);

export const hasMixin = <M>(instance: any, mixin: new (...args) => M): instance is M => {
export const hasMixin = <M>(instance: any, mixin: abstract new (...args) => M): instance is M => {
if (instance instanceof mixin)
return true;

Expand Down
7 changes: 7 additions & 0 deletions test/integration/has-mixin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ describe('hasMixin(...)', () => {
expect(hasMixin(fooBar, Bar)).to.be.true;
});

it('should work with abstract classes', () => {
abstract class Baz {}
class FooBaz extends Mixin(Foo, Baz) {}
const fooBaz: any = new FooBaz();
expect(hasMixin(fooBaz, Baz)).to.be.true;
});

it('should work for cases where the mixin is buried deep in the proto chain', () => {
class Foo1 {}
class Bar1 {}
Expand Down

0 comments on commit 8964b59

Please sign in to comment.