Search code examples
javascriptcommentsjsdoc

what does an exclamation mark indicate in javascript @param and @return comments?


I'm trying to follow this guideline:

/** A class that does something. */
class SomeClass extends SomeBaseClass {
  /**
   * Operates on an instance of MyClass and returns something.
   * @param {!MyClass} obj An object that for some reason needs detailed
   *     explanation that spans multiple lines.
   * @param {!OtherClass} obviousOtherClass
   * @return {boolean} Whether something occurred.
   */
  someMethod(obj, obviousOtherClass) { ... }

  /** @override */
  overriddenMethod(param) { ... }
}

/**
 * Demonstrates how top-level functions follow the same rules.  This one
 * makes an array.
 * @param {TYPE} arg
 * @return {!Array<TYPE>}
 * @template TYPE
 */
function makeArray(arg) { ... }

and I want to know what does the exclamation mark means in @param {!MyClass} or @return {!Array<TYPE>} and when to use it.


Solution

  • According to the table on Use JSDoc: @type, at the row for "Non-nullable type", a preceding exclamation mark means "non-null".