pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 API: pm2.start Typescript type uses incorrect type for callback

Open RedNuttyGuy opened this issue 3 years ago • 3 comments

What's going wrong?

In Typescript, pm2.start(options, cb) or any of its overloads uses the callback signature (err, proc) => void which, during testing, I found the proc parameter actually gets assigned a pm2.Proc[] rather than a single pm2.Proc.

This causes Typescript errors during compilation as the type being assigned to the property is not what is actually assigned

How could we reproduce this issue?

Call pm2.start(options, (err, proc) => { console.log(proc) }) and view that the value is an array of Proc objects.

Supporting information

N/A

RedNuttyGuy avatar Jun 19 '21 05:06 RedNuttyGuy

The same problem is occuring for the Error passed in the callback. It is not a single error, but rather an array of errors (when using a config json file).

Reproducible example

pm2.start('config.json', (e, proc) => console.log({ e })))

Outputs:

{
    e: [
        Error...
    ]
}

Note that e is an array of errors, NOT a single error as the typescript types would indicate.

I'm not sure if this only occurs when a config file of multiple jobs is used, or if its always the case?

mrbrianevans avatar Jun 14 '22 13:06 mrbrianevans

Someone submitted a PR for this specific issue: https://github.com/Unitech/pm2/pull/5502

bathtaters avatar Mar 27 '23 00:03 bathtaters