How can I describe what parameters my function requires and make them viewable when i type my code?
- For example, lets say I want to hint what parameters a callback function would take. If we look at ExpressJS render function below, it shows exactly what the callback accepts and would return.
- Mine however only says (cb1: any) despite that this callback is supposed to return 2 parameters (error and data). Is there any special way to define it?
Currently the code in my Product model for this function looks like this. How can I define the callback function in a way that it would hint what it returns?
static findById(id, cb1) {
fs.readFile("./src/database/products.json", (err, data) => {
if (err) {
cb1(err, product);
} else {
const products = JSON.parse(data);
const product = products.find(p => p.id == id);
cb1(err, product);
}
});
};