This is Microsoft’s official code https://github.com/Microsoft/...
During the learning process, I saw this bit operator (&) code and said I couldn’t understand it. Can you give me an answer? What is the meaning of this code?
Thank you.
type UserModel What type is this defined?
Also, mongoose.Document & {} returns 0 or 1? But in the case of {}&{}, all returns are 0, right?
Rookies don’t really understand.
In typescript, the & operator is used between two types to represent cross types, instead of the & bit operation of js
Cross type can be simply understood as a type that has all members of multiple types at the same time
For example, in the code in the picture, the type UserModel has all the members of mongoose.Document and all the members defined in {} later
See the official documentation here