Reputation: 599
I have been looking at using typescript with mongoose for MongoDB. Mostly it has been working great, but with certain types of quesites I get warnings from the typescript compiler.
If I do an or like so:
{"$or": [{done: {"$exists": false}}, {done:false}]}
I get the following warning:
Incompatible types in array literal expression: Types of property 'done' of types '{ done: { $exists: bool; }; }' and '{ done: bool; }' are incompatible.
I understand why, but is there a way to express this so the compiler will accept it?
Upvotes: 17
Views: 16851
Reputation: 220954
You can type-assert any of the elements to any
to "turn off" type checking:
[<any>{done: {"$exists": false}}, {done:false}]
Or, if you're initializing a variable, you can do something like this:
var n: any[] = [{done: {"$exists": false}}, {done:false}]
Upvotes: 32