pm2
pm2 copied to clipboard
PM2 API: pm2.start Typescript type uses incorrect type for callback
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
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?
Someone submitted a PR for this specific issue: https://github.com/Unitech/pm2/pull/5502