I'm trying out a little side project with the MEAN stack and Typescript, and I've seem to run into an issue regarding Typescript not picking up on the typings for the emit()
and Array.sum()
methods.
Here's my code below...
let options: mongoose.ModelMapReduceOption<IInvoice, any, any> = {
map: () => {
emit(this.customer, this.total);
},
reduce: (key, values) => {
return Array.sum(values);
},
out: { replace: "map_reduce_customers" },
verbose: true
};
I am using the typings package on NPM, and have installed the typings for the mongodb as well as mongoose packages in my project. There are red squigglies under these two methods, yet the application works just fine when I run.
And yes, it is correctly transpiled to valid JavaScript. I would just like to know if there's a typing definition I'm missing for Typescript to pick up on these two methods?
You can declare the emit function like this
declare function emit(k, v);
and then use non-arrow functions (to be able to use "this" inside the map function)
map: function map() {
emit(this.customer, this.total);
}
Array.sum
does not exist in JS as far as I know. If it's being provided by a library, you may want to install the typings for that library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With