-
For the types
string,number,booleanandfunction, the!shall be written explicitly.Example:
/**@type {!Array.<!function(!string):!boolean>}*/to type an object as array of functions which require astringvalue, notnullorundefinedas argument and always return abooleanvalue, nevernullorundefinedRationale: While for
string,numberandbooleantypes it is rather weird to have thenullvalue, it is still better to write the default explicitely, to prevent errors like seen in Closure Compiler's own externs declarations and for consistenty with the rules 2) to 4).
(Agreed on in "coding rules for types" ml thread)
-
For the types
Object,ArrayandFunction, the?shall be written explicitly.Example:
/**@return {?Node}*/to define that a method returns either an object of typeNodeor valuenullRationale: Null pointers can be a problem. The compiler checks the nullness when passing an object but not when accessing a member. Keeping awareness of nullness high is good.
(Agreed on in "coding rules for types" ml thread)
- Objects will always explicitly have
stringas the key. So each Object in a type definition starts withObject.<!string,.
Rationale: Any other type makes no sense, because in JavaScript the key type is always a string anyway.
(Agreed on in "coding rules for types" ml thread)
- Each non-constructor function must have a
@returndeclaration.
Example: /**@return {undefined}*/ to define that a method returns always undefined, which is also the default
Rationale: Being explicit about what a function returns avoids any ambiguity about whether the @return declaration was just forgotten or what the exact default is
(Agreed on in "coding rules for types" ml thread)