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.
PHP中文网
PHP中文网 2017-06-10 09:47:59
0
1
728

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中文网

认证高级PHP讲师

reply all(1)
滿天的星座

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!