Skip to content

Commit a26114e

Browse files
johnjenkinsJohn Jenkins
andauthored
fix(Mixin): export MixinFactory type for ease of use (#6390)
* fix(Mixin): export `MixinFactory` for ease of use * chore: prettier * chore: loosen type slightly --------- Co-authored-by: John Jenkins <[email protected]>
1 parent 77cfdb3 commit a26114e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/declarations/stencil-public-runtime.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ declare type CustomMethodDecorator<T> = (
66

77
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
88

9-
type MixinFactory = <TBase extends abstract new (...args: any[]) => any>(
10-
base: TBase,
11-
) => abstract new (...args: ConstructorParameters<TBase>) => any;
12-
139
export interface ComponentDecorator {
1410
(opts?: ComponentOptions): ClassDecorator;
1511
}
@@ -407,15 +403,21 @@ export declare function readTask(task: RafCallback): void;
407403
*/
408404
export declare const setErrorHandler: (handler: ErrorHandler) => void;
409405

406+
export type MixinFactory = <TBase extends new (...args: any[]) => any>(
407+
base: TBase,
408+
) => abstract new (...args: ConstructorParameters<TBase>) => any;
409+
410410
/**
411411
* Compose multiple mixin classes into a single constructor.
412412
* The resulting class has the combined instance types of all mixed-in classes.
413413
*
414414
* Example:
415415
* ```
416-
* const AWrap = (Base) => {class A extends Base { propA = A }; return A;}
417-
* const BWrap = (Base) => {class B extends Base { propB = B }; return B;}
418-
* const CWrap = (Base) => {class C extends Base { propC = C }; return C;}
416+
* import { Mixin, MixinFactory } from '@stencil/core';
417+
*
418+
* const AWrap: MixinFactory = (Base) => {class A extends Base { propA = A }; return A;}
419+
* const BWrap: MixinFactory = (Base) => {class B extends Base { propB = B }; return B;}
420+
* const CWrap: MixinFactory = (Base) => {class C extends Base { propC = C }; return C;}
419421
*
420422
* class X extends Mixin(AWrap, BWrap, CWrap) {
421423
* render() { return <div>{this.propA} {this.propB} {this.propC}</div>; }

src/internal/stencil-core/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export {
4040
Listen,
4141
Method,
4242
Mixin,
43+
MixinFactory,
4344
Prop,
4445
readTask,
4546
render,

0 commit comments

Comments
 (0)