search

Home  >  Q&A  >  body text

node.js - When I was learning typescript to write the node interface, I was confused when I saw a piece of code. Guys, please give me the answer.

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.

PHP中文网PHP中文网2751 days ago840

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-06-10 09:49:59

    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

    reply
    0
  • Cancelreply