-
-
Notifications
You must be signed in to change notification settings - Fork 750
Description
Hello,
It seems typedoc does not support documenting typescript mixins? Or it can be done with some clever trick? Please advise.
Mixin pattern
The mixin pattern in TypeScript can be defined like this:
Supporting definitions:
export type AnyFunction<A = any> = (...input: any[]) => A
export type AnyConstructor<A = object> = new (...input: any[]) => A
export type Mixin<T extends AnyFunction> = InstanceType<ReturnType<T>>export const MyMixin =
<T extends AnyConstructor<AlreadyImplements & BaseClass>>(base : T) =>
// internal mixin class
class MyMixin extends base {
someProperty : string = 'initialValue'
someMethod() {
}
}
// the "instance type" of this mixin
export type MyMixin = Mixin<typeof MyMixin>
// or (supports recursive type definition)
export interface MyMixin extends Mixin<typeof MyMixin> {}Sample 1
The sample mixins can be found here: https://github.com/bryntum/chronograph/blob/master/src/graph/Node.ts#L5
In this example, we define the WalkableForwardNode mixin, which includes (or must already implement) WalkableForward mixin and enhances it with some additional logic.
Currently typedoc does not recognize it at all, all we have is the documentation of the mixin function:

No documentation is available for the internal mixin class, which is the most important piece of the mixin. Also, there's no docs for the mixin instance type alias. It does not appear in the docs index at all.
Sample 2
One can also use the interface to declare the type of the mixin instance: https://github.com/bryntum/chronograph/blob/master/src/chrono/Atom.ts#L182
This is an alternative notation, which allows for recursive type definitions. It does appear in the docs, however it does not contain the properties of the mixin class:

Reproduce
To reproduce you can clone the chronograph: https://github.com/bryntum/chronograph/
Then, npm install and npm run docs
Mixins are very flexible and type-safe way of combining behaviors, they should be supported by the typedoc I think. I'm very interested in this feature and volunteering for any helper tasks, just ping me nickolay8@gmail.com