简体   繁体   中英

Meaning of < and > in JavaScript export or function definitions

In javascript codes, I see statements like this:

export default mongoose.model<UserInterface & mongoose.Document>('User', UserSchema)

this example is taken from repo: https://github.com/santiq/nodejs-auth.git

It would be great if someone could explain what <UserInterface & mongoose.Document> means? You can find similar statements, ie Promise<any> few times in the same repo. It is not the first time I see this kind of statement and I cannot find any explanation of it. Since I am learning JavaScript very actively it is important for me to understand advanced syntax and any "ninja" codes.

Thanks in advance Jo

That's not JavaScript, that's TypeScript.

In this case, it's declaring that the module's default exported item is a model object that concerns any object that has members belonging to both UserInterface and Document simultaneously.

That is great help guys. Great thanks. I didn't expected that answer. I went through internet back and forth with no answer for my question simply because I did not consider that it could be anything else than JS.

Thanks a million Jo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM