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

How to document a type? #278

Closed
vekexasia opened this issue Aug 18, 2016 · 7 comments
Closed

How to document a type? #278

vekexasia opened this issue Aug 18, 2016 · 7 comments

Comments

@vekexasia
Copy link

I've a type used in a class

type MyType {
    haha: number,
    optional?: string
}
class MyClass{
    constructor(private config: MyType) {
    }
}

How to document MyType to explain what haha and optional are used for?

@aciccarello
Copy link
Collaborator

I would use and interface for MyType and put JSDoc comments on the properties. Also, have you tried an @param jsdoc comment on the constructor?

/** Description of MyType interface */
interface MyType {
    /** This property is ... */
    haha: number,
    /** Optional property useful for ... */
    optional?: string
}

/**
 * Description of what MyClass is
 */
class MyClass{
    /**
     * @param config Docs on config property.It is different than the interface docs
     */
    constructor(private config: MyType) {
    }
}

@vekexasia
Copy link
Author

Thanks @aciccarello ... Would you please explain me what's the difference between a type and an interface?

@aciccarello
Copy link
Collaborator

aciccarello commented Aug 18, 2016

I believe types were introduced later for some specific use cases like type aliases. This SO questions has a good answer describing the differences. Generally I use interfaces for most cases and then use a type if I want an alias, such as getting the type of a specific interface property.

Interface types have many similarities to type aliases for object type literals, but since interface types offer more capabilities they are generally preferred to type aliases.
StackOverflow: Typescript: Interfaces vs Types

@vekexasia
Copy link
Author

Thank you :) @aciccarello

@giannif
Copy link

giannif commented Apr 22, 2019

Anyone know if you can document a type like the original question asks? I have lots of types, and I'm interested in documenting them

@maksnester
Copy link

That still doesn't really have an answer. So it should be an issue because there are no docs for type properties.
It's possible to document an interface, but inline docs for properties won't work for types. The only option, for now, is to duplicate it with jsdoc like.

/**
 * @property foo Some docs.
 */
type MyFooType = {
  /** that comment is ignored */
  foo:? string;
}

@crhistianramirez
Copy link

@maksnester is this still working for you? I'm trying your workaround and the name is being excluded.

image

image

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

5 participants