2

In my Angular9 and Angular10 projects I was able to create mixins using the below steps from Harnessing the power of Mixins in Angular blog

constructor.mixin.ts

export type Constructor<T = {}> = new (...args: any[]) => T;

my-mixin.mixin.ts

import {Constructor} from './constructor.mixin';
import {BehaviorSubject} from 'rxjs';

export const myMixin = <T extends Constructor>(BaseClass: T = class { } as T) =>
  class extends BaseClass {
    title = 'Title in the mixin';
    titleUpdateSubject$ = new BehaviorSubject('');
    title$ = this.typedTitleSubject$.asObservable();
  };

This worked fine till I updated angular following the steps in Angular Update Guide

After a successful change from TSLint to ESLint following Migrating an Angular CLI project from Codelyzer and TSLint and running linting (npx ng lint my-project-name --fix) I receive the below error

1:29 error Don't use {} as a type. {} actually means "any non-nullish value".

  • If you want a type meaning "any object", you probably want Record<string, unknown> instead.
  • If you want a type meaning "any value", you probably want unknown instead @typescript-eslint/ban-types

The error is being thrown on the line export type Constructor<T = {}> = new (...args: any[]) => T;

My problem is how I can refactor this line to satisfy typescript. Unfortunately I am unable to find an answer with my use case e.g in TypeScript '{}' type is about how to type non nullish value.

Owen Kelvin
  • 14,054
  • 10
  • 41
  • 74

0 Answers0