I have seen Google using a lot of Type Expressions in various APIs. Can someone explain to me what good they do? Are they only there to highlight/colorcode a certain functions, or ease readability? Or do they serve some actual purpose?
I'm a bit confused as they're used as together with commented-out code but differ from regular comments with /** @type */ instead of /* @type */ (which do not color-code the comment)
Could someone give me the how's and why's of Type Expressions?
1 Answer 1
You will see these in a lot of places other than Google. They can be used for Closure Compiler to improve optimization and also provide a bit of type safety by warning when there are type errors.
But more generally these are JSDoc tags, which allow you to annotate and describe javascript code. The tags can document what types of data you code expects to receive and what will be returned. This can then be used to automatically produce documentation about your code and can also be used by text editors and IDEs to give feedback while working. Many popular editors support this such as Sublime Text and Visual Studio.
Lots of information here: http://usejsdoc.org/index.html
pushonwindowobject.