Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does esdoc-typescript-plugin allow me to hand write JSDoc/TSDoc without types getting in the way? #90

Open
trusktr opened this issue Aug 11, 2019 · 0 comments

Comments

@trusktr
Copy link

trusktr commented Aug 11, 2019

I have "mixin classes" (class-factory mixins), but I just want to document them as regular classes, and use things like @mixes (or similar) to describe what they inherit from. I don't care about having to duplicate types in my comments, if it means I can have control and can shape the documentation output by hand.

The reason is, the end use case of my (mixin) classes is for them to be custom elements. The mixin functionality is only for combining classes together during implementation mostly (though a discerning intellisense user will be able to pick up on and use the mixin patterns).

Basically, I have classes that can be used like this:

import {Transformable} from './Transformable'

// instantiate one:
const f = new Transformable

// extend it like a regular class
class Foo extends Transformable {}

// or mix it with other classes:
class Bar {}
class Baz extends Transformable.mixin(Bar) {}

Where I want to document the Transformable class something like the following:

import {TreeNode} from './TreeNode'
import {Sizeable} from './Sizeable'
import {Constructor, Mixin, MixinResult} from 'lowclass'

/**
 * @class Transformable
 * @mixin
 * @mixes TreeNode
 * @mixes Sizeable
 */
function TransformableMixin<T extends Constructor>(Base: T) {

    // The Transformable mixin class is composed from TreeNode and Sizeable mixin classes
    const Parent = TreeNode.mixin(Sizeable.mixin(Constructor(Base)))

    class Transformable extends Parent {
        /**
         * Set the position of the Transformable.
         *
         * @property position
         * @memberof Transformable
         * @type {SomeType}
         */
        set position(newValue: any) {
            this._setPropertyXYZ<Transformable, TransformProp>('position', newValue)
        }
        get position(): any {
            return this._props.position
        }

        // ... etc ...
    }

    return Transformable as MixinResult<typeof Transformable, T>
}

// this actually creates the class reference.
export const Transformable = Mixin(TransformableMixin)
export interface Transformable extends InstanceType<typeof Transformable> {}

See what I'm trying to do there?

Basically, I'd like to use @mixes (or something) for multiple inheritance. I'd like to be able to represent this in the docs somehow (f.e. like one class with multiple arrows pointing to the other classes, or something).

In the end, a user will only use the class instances directly, and won't necessarily even need to know about the mixin functionality:

// `mesh` inherits from Transformable, and possibly from something else.
const mesh = document.querySelector('box-mesh')

// but in the end, the user reading docs just needs to know about the classes, and their inherited properties.
// Under the hood the instances are composed from mixin classes, but that's not important here, and things like
// TypeDoc try to document every aspect possible, including mixin machinery.

// The user just needs to do this, for example:
mesh.position = {y: 20}

So I'm aiming to make the docs really simple. I really don't want to throw an HTML beginner at some TypeDoc docs (I hope you know what I mean).

Seems like what I need is for some parser to parse JSDoc comments out of my TypeScript files, then I should handle the rest myself? I've had no luck with that so far.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant