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?
You can ignore type checking errors for a single line by using the // @ts-ignore comment. Copied! The // @ts-ignore comment ignores any type checking errors that occur on the next line. If you use a linter, you might get an error when you use a comment to disable type checking for a line, or for the entire file.
Use the // @ts-nocheck comment to disable type checking for an entire file in TypeScript. The // @ts-nocheck comment instructs TypeScript to skip the file when type checking.
Typings is the simple way to manage and install TypeScript definitions. It uses typings. json , which can resolve to the Typings Registry, GitHub, NPM, Bower, HTTP and local files. Packages can use type definitions from various sources and different versions, knowing they will never conflict for users.
Use the Record utility type to enforce the type of an object's values in TypeScript, e.g. type Animal = Record<string, string> . The Record utility type constructs an object type, whose keys and values are of specific type.
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}]
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