diff --git a/src/declarations/stencil-public-runtime.ts b/src/declarations/stencil-public-runtime.ts index fa1e8de0010..63f783b2310 100644 --- a/src/declarations/stencil-public-runtime.ts +++ b/src/declarations/stencil-public-runtime.ts @@ -4,7 +4,9 @@ type CustomMethodDecorator = ( descriptor: TypedPropertyDescriptor, ) => TypedPropertyDescriptor | void; -type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never; +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; + +type MixinInstance = F extends (base: MixedInCtor) => MixedInCtor ? I : never; export interface ComponentDecorator { (opts?: ComponentOptions): ClassDecorator; @@ -425,21 +427,31 @@ export declare function readTask(task: RafCallback): void; */ export declare const setErrorHandler: (handler: ErrorHandler) => void; -export type MixinFactory = any>( - base: TBase, -) => abstract new (...args: ConstructorParameters) => any; +/** + * @deprecated - Use `MixedInCtor` instead: + * ```ts + * import { MixedInCtor } from '@stencil/core'; + * + * const AFactoryFn = (Base: B) => {class A extends Base { propA = A }; return A;} + * ``` + */ +export type MixinFactory = (base: MixedInCtor) => MixedInCtor; + +// TODO ^ do not remove. Just do not export when deprecated. + +export type MixedInCtor = new (...args: any[]) => T; /** * Compose multiple mixin classes into a single constructor. * The resulting class has the combined instance types of all mixed-in classes. * * Example: - * ``` - * import { Mixin, MixinFactory } from '@stencil/core'; + * ```ts + * import { Mixin, MixedInCtor } from '@stencil/core'; * - * const AWrap: MixinFactory = (Base) => {class A extends Base { propA = A }; return A;} - * const BWrap: MixinFactory = (Base) => {class B extends Base { propB = B }; return B;} - * const CWrap: MixinFactory = (Base) => {class C extends Base { propC = C }; return C;} + * const AWrap = (Base: B) => {class A extends Base { propA = A }; return A;} + * const BWrap = (Base: B) => {class B extends Base { propB = B }; return B;} + * const CWrap = (Base: B) => {class C extends Base { propC = C }; return C;} * * class X extends Mixin(AWrap, BWrap, CWrap) { * render() { return
{this.propA} {this.propB} {this.propC}
; } @@ -447,11 +459,11 @@ export type MixinFactory = any>( * ``` * * @param mixinFactories mixin factory functions that return a class which extends from the provided class. - * @returns a class that that is composed from extending each of the provided classes in the order they were provided. + * @returns a class that is composed from extending each of the provided classes in the order they were provided. */ -export declare function Mixin( +export declare function Mixin( ...mixinFactories: TMixins -): abstract new (...args: any[]) => UnionToIntersection>>; +): abstract new (...args: any[]) => UnionToIntersection>; /** * This file gets copied to all distributions of stencil component collections. diff --git a/src/internal/stencil-core/index.d.ts b/src/internal/stencil-core/index.d.ts index b94ae7db8d5..4a36467e680 100644 --- a/src/internal/stencil-core/index.d.ts +++ b/src/internal/stencil-core/index.d.ts @@ -41,6 +41,7 @@ export { Host, Listen, Method, + MixedInCtor, Mixin, MixinFactory, Prop,