Version: 0.1.00.1.10.2.00.2.10.2.20.2.30.2.40.3.00.3.10.4.00.4.10.4.20.4.30.5.00.5.10.5.20.6.00.6.10.7.00.8.00.8.10.8.20.8.30.8.40.8.50.8.60.8.70.8.80.9.00.10.00.10.10.10.20.10.30.11.00.11.10.11.20.11.30.11.40.11.50.11.60.11.70.11.80.11.90.11.100.11.110.11.120.11.130.11.140.11.150.11.160.11.170.12.01.0.01.0.11.1.01.1.11.1.21.1.31.1.41.1.51.1.61.1.71.1.81.2.01.2.11.3.01.4.01.4.11.5.01.6.01.6.11.6.21.6.31.7.01.7.11.7.21.7.31.8.01.8.11.8.21.8.31.8.41.8.51.8.61.8.71.9.01.9.21.9.31.10.01.10.11.10.21.10.31.10.41.10.51.10.61.10.71.11.01.12.01.12.11.12.21.12.31.12.42.0.02.1.02.2.02.2.12.3.02.4.02.4.12.4.22.5.02.6.02.7.02.7.12.8.02.9.02.9.12.9.22.9.32.9.42.9.52.10.02.10.12.11.02.12.02.13.02.13.12.14.02.14.12.15.02.15.12.16.02.16.12.16.22.17.02.18.03.0.03.0.13.1.03.1.13.1.24.0.0-alpha.14.0.0-alpha.24.0.0-alpha.34.0.0-alpha.44.0.0-alpha.54.0.0-alpha.64.0.0-alpha.74.0.0-alpha.84.0.0-alpha.94.0.0-alpha.104.0.0-alpha.114.0.0-alpha.124.0.0-alpha.134.0.0-alpha.144.0.0-alpha.154.0.0-alpha.164.0.0-alpha.174.0.0-alpha.184.0.0-alpha.194.0.0-alpha.204.0.0-alpha.214.0.0-alpha.224.0.0-alpha.234.0.0-alpha.244.0.0-alpha.254.0.0-alpha.264.0.0-alpha.274.0.0-alpha.284.0.0-alpha.294.0.0-alpha.304.0.0-alpha.314.0.0-alpha.324.0.0-alpha.334.0.0-alpha.344.0.04.0.14.0.24.0.34.0.44.0.54.0.64.0.74.0.84.0.94.0.105.0.05.1.05.1.15.1.25.1.35.1.45.1.56.0.06.0.16.0.26.1.06.1.16.1.26.1.36.1.46.1.56.1.6
import { Constructor } from '@loopback/context';
/**
* A replacement for `typeof Target` to be used in mixin class definitions.
* This is a workaround for TypeScript limitation described in
* - https://github.com/microsoft/TypeScript/issues/17293
* - https://github.com/microsoft/TypeScript/issues/17744
* - https://github.com/microsoft/TypeScript/issues/36060
*
* @example
* ```ts
* export function MyMixin<T extends MixinTarget<Application>>(superClass: T) {
* return class extends superClass {
* // contribute new class members
* }
* };
* ```
* TypeScript does not allow class mixins to access protected members from
* the base class. You can use the following approach as a workaround:
* // eslint-disable-next-line @typescript-eslint/ban-ts-comment
* // @ts-ignore
* (this as unknown as {YourBaseClass}).protectedMember
* The directive `@ts-ignore` suppresses compiler error about accessing
* a protected member from outside. Unfortunately, it also disables other
* compile-time checks (e.g. to verify that a protected method was invoked
* with correct arguments, and so on). This is the same behavior you
* would get by using `Constructor<any>` instead of `MixinTarget<Application>`.
* The major improvement is that TypeScript can still infer the return
* type of the protected member, therefore `any` is NOT introduced to subsequent
* code.
* TypeScript also does not allow mixin class to overwrite a method inherited
* from a mapped type, see https://github.com/microsoft/TypeScript/issues/38496
* As a workaround, use `@ts-ignore` to disable the error.
* export function RepositoryMixin<T extends MixinTarget<Application>>(
* superClass: T,
* ) {
* public component<C extends Component = Component>(
* componentCtor: Constructor<C>,
* nameOrOptions?: string | BindingFromClassOptions,
* const binding = super.component(componentCtor, nameOrOptions);
* // ...
* return binding;
*/
export type MixinTarget<T extends object> = Constructor<{
[P in keyof T]: T[P];
}>;