esdoc / esdoc-plugins

MIT License
140 stars 77 forks source link

[Typescript Plugin] - Spread operator not handled #66

Open qbodart opened 5 years ago

qbodart commented 5 years ago

I have a function in typescript that returns a promise. The spread operator is used to merge properties of two objects. ESDoc fails on that line and runs smoothly when I cut it.

return new Promise((resolve, reject) => {
    this.service.findByUserId(userId, relationsUser)
    .then(async (user: User) => {
        if (!user) throw new NotFoundException('User does not exist');
        const authUser = await this.service.getAuth0UserProfile(user.userId);
        resolve({ ...authUser, ...user}); <-- Does not work
    })
    .catch(reason => reject(reason));
});

Any idea how to solve this? Thanks!

ziuniecki commented 5 years ago

I have the same problem :/ any ideas?

OK I found how to solve this problem. I installed this plugin: https://github.com/esdoc/esdoc-plugins/tree/master/esdoc-ecmascript-proposal-plugin

and now my .esdoc.json is:

{
    "source": "./src",
    "destination": "./docs",
    "includes": [
        "\\.ts$"
    ],
    "excludes": [
        "\\.config\\.ts$"
    ],
    "plugins": [
        {
            "name": "esdoc-ecmascript-proposal-plugin",
            "option": {
                "classProperties": true,
                "objectRestSpread": true,
                "doExpressions": true,
                "functionBind": true,
                "functionSent": true,
                "asyncGenerators": true,
                "decorators": true,
                "exportExtensions": true,
                "dynamicImport": true
            }
        },
        {
            "name": "esdoc-typescript-plugin",
            "option": {
                "enable": true
            }
        },
        {
            "name": "esdoc-standard-plugin"
        }
    ]
}

And no problem with spread operators :)

qbodart commented 5 years ago

I solved it by using Object.assign().

bbugh commented 5 years ago

@ziunio workaround didn't work for me. In my case, I have functions with spread parameters with Types that esdoc is resulting in "undefined". This function:

thing (...thingConstructors: ThingConstructor<Thing>[]): number[] {

generates this documentation:

public thing(thingConstructors: undefined): *

Whether I use that plugin or not.