Annotation updates

Change-Id: I146f76b9dcc1a92e18acec01481ad280fb431868
diff --git a/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.js b/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.js
index d33ed23..ef39e1f 100644
--- a/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.js
+++ b/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.js
@@ -20,9 +20,13 @@
     is: 'gr-comment-api',
 
     properties: {
+      /** @type {number} */
       _changeNum: Number,
+      /** @type {!Object|undefined} */
       _comments: Object,
+      /** @type {!Object|undefined} */
       _drafts: Object,
+      /** @type {!Object|undefined} */
       _robotComments: Object,
     },
 
@@ -35,7 +39,7 @@
      * number. The returned promise resolves when the comments have loaded, but
      * does not yield the comment data.
      *
-     * @param {!number} changeNum
+     * @param {number} changeNum
      * @return {!Promise}
      */
     loadAll(changeNum) {
@@ -91,7 +95,7 @@
      * @param {!string} path
      * @param {!Object} patchRange The patch-range object containing patchNum
      *     and basePatchNum properties to represent the range.
-     * @param {Object} opt_projectConfig Optional project config object to
+     * @param {Object=} opt_projectConfig Optional project config object to
      *     include in the meta sub-object.
      * @return {Object}
      */
@@ -160,7 +164,7 @@
      * Whether the given comment should be included in the given patch range.
      * @param {!Object} comment
      * @param {!Object} range
-     * @return {boolean}
+     * @return {boolean|undefined}
      */
     _isInPatchRange(comment, range) {
       return this._isInBaseOfPatchRange(comment, range) ||
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html
index 22e5080..f11b573 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html
@@ -393,7 +393,7 @@
         },
 
         /**
-         * @return {Boolean} whether any of the lines in _groups are longer
+         * @return {boolean} whether any of the lines in _groups are longer
          * than SYNTAX_MAX_LINE_LENGTH.
          */
         _anyLineTooLong() {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js
index a9438bb7..40fcf0d 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js
@@ -153,12 +153,12 @@
   /**
    * Find line elements or line objects by a range of line numbers and a side.
    *
-   * @param {Number} start The first line number
-   * @param {Number} end The last line number
-   * @param {String} opt_side The side of the range. Either 'left' or 'right'.
-   * @param {Array<GrDiffLine>} out_lines The output list of line objects. Use
+   * @param {number} start The first line number
+   * @param {number} end The last line number
+   * @param {string} opt_side The side of the range. Either 'left' or 'right'.
+   * @param {!Array<GrDiffLine>} out_lines The output list of line objects. Use
    *     null if not desired.
-   * @param  {Array<HTMLElement>} out_elements The output list of line elements.
+   * @param  {!Array<HTMLElement>} out_elements The output list of line elements.
    *     Use null if not desired.
    */
   GrDiffBuilder.prototype.findLinesByRange = function(start, end, opt_side,
@@ -443,7 +443,7 @@
 
   /**
    * Returns the text length after normalizing unicode and tabs.
-   * @return {Number} The normalized length of the text.
+   * @return {number} The normalized length of the text.
    */
   GrDiffBuilder.prototype._textLength = function(text, tabSize) {
     text = text.replace(REGEX_ASTRAL_SYMBOL, '_');
@@ -536,9 +536,9 @@
    * elements in place of tab characters. In each case tab elements are given
    * the width needed to reach the next tab-stop.
    *
-   * @param {String} A line of text potentially containing tab characters.
-   * @param {Number} The width for tabs.
-   * @return {String} An HTML string potentially containing tab elements.
+   * @param {string} A line of text potentially containing tab characters.
+   * @param {number} The width for tabs.
+   * @return {string} An HTML string potentially containing tab elements.
    */
   GrDiffBuilder.prototype._addTabWrappers = function(line, tabSize) {
     if (!line.length) { return ''; }
@@ -600,7 +600,7 @@
    * Finds the next DIV.contentText element following the given element, and on
    * the same side. Will only search within a group.
    * @param {HTMLElement} content
-   * @param {String} side Either 'left' or 'right'
+   * @param {string} side Either 'left' or 'right'
    * @return {HTMLElement}
    */
   GrDiffBuilder.prototype._getNextContentOnSide = function(content, side) {
@@ -610,8 +610,8 @@
   /**
    * Determines whether the given group is either totally an addition or totally
    * a removal.
-   * @param {GrDiffGroup} group
-   * @return {Boolean}
+   * @param {!Object} group (GrDiffGroup)
+   * @return {boolean}
    */
   GrDiffBuilder.prototype._isTotal = function(group) {
     return group.type === GrDiffGroup.Type.DELTA &&
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js
index d8dccad..e9ab3d6 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js
@@ -213,6 +213,9 @@
       return !!comment.__draft;
     },
 
+    /**
+     * @param {boolean=} opt_quote
+     */
     _processCommentReply(opt_quote) {
       const comment = this._lastComment;
       let quoteStr;
@@ -273,6 +276,10 @@
       return d;
     },
 
+    /**
+     * @param {number=} opt_lineNum
+     * @param {!Object=} opt_range
+     */
     _newDraft(opt_lineNum, opt_range) {
       const d = {
         __draft: true,
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
index dcba80d..4f0ebcc 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
@@ -53,6 +53,7 @@
 
     properties: {
       changeNum: String,
+      /** @type {?} */
       comment: {
         type: Object,
         notify: true,
@@ -88,6 +89,7 @@
         value: true,
         observer: '_toggleCollapseClass',
       },
+      /** @type {?} */
       projectConfig: Object,
       robotButtonDisabled: Boolean,
       _isAdmin: {
@@ -215,6 +217,11 @@
       }
     },
 
+    /**
+     * @param {!Object=} opt_mixin
+     *
+     * @return {!Object}
+     */
     _getEventPayload(opt_mixin) {
       return Object.assign({}, opt_mixin, {
         comment: this.comment,
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js
index e47db8f..b14ea7f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js
@@ -43,6 +43,7 @@
         type: String,
         value: DiffSides.RIGHT,
       },
+      /** @type {!HTMLElement|undefined} */
       diffRow: {
         type: Object,
         notify: true,
@@ -61,6 +62,8 @@
        * If set, the cursor will attempt to move to the line number (instead of
        * the first chunk) the next time the diff renders. It is set back to null
        * when used.
+       *
+       * @type (?number)
        */
       initialLineNumber: {
         type: Number,
@@ -147,6 +150,11 @@
       this._fixSide();
     },
 
+    /**
+     * @param {number} number
+     * @param {string} side
+     * @param {string=} opt_path
+     */
     moveToLineNumber(number, side, opt_path) {
       const row = this._findRowByNumberAndFile(number, side, opt_path);
       if (row) {
@@ -157,7 +165,7 @@
 
     /**
      * Get the line number element targeted by the cursor row and side.
-     * @return {DOMElement}
+     * @return {?Element|undefined}
      */
     getTargetLineElement() {
       let lineElSelector = '.lineNum';
@@ -221,7 +229,7 @@
      * Get a short address for the location of the cursor. Such as '123' for
      * line 123 of the revision, or 'b321' for line 321 of the base patch.
      * Returns an empty string if an address is not available.
-     * @return {String}
+     * @return {string}
      */
     getAddress() {
       if (!this.diffRow) { return ''; }
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-annotation.js b/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-annotation.js
index 9afbf2b..e18f6ca 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-annotation.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-annotation.js
@@ -28,8 +28,8 @@
     /**
      * The DOM API textContent.length calculation is broken when the text
      * contains Unicode. See https://mathiasbynens.be/notes/javascript-unicode .
-     * @param  {Text} A text node.
-     * @return {Number} The length of the text.
+     * @param  {!Text} node text node.
+     * @return {number} The length of the text.
      */
     getLength(node) {
       return this.getStringLength(node.textContent);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-diff-highlight.js b/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-diff-highlight.js
index 3288608..2490509 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-diff-highlight.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-diff-highlight.js
@@ -20,6 +20,11 @@
     properties: {
       comments: Object,
       loggedIn: Boolean,
+      /**
+       * querySelector can return null, so needs to be nullable.
+       *
+       * @type {?HTMLElement}
+       * */
       _cachedDiffBuilder: Object,
       isAttached: Boolean,
     },
@@ -99,7 +104,7 @@
      * Merges multiple ranges, accounts for triple click, accounts for
      * syntax highligh, convert native DOM Range objects to Gerrit concepts
      * (line, side, etc).
-     * @return {{
+     * @return {({
      *   start: {
      *     node: Node,
      *     side: string,
@@ -112,7 +117,7 @@
      *     line: Number,
      *     column: Number
      *   }
-     * }}
+     * })|null|!Object}
      */
     _getNormalizedRange() {
       const selection = window.getSelection();
@@ -134,6 +139,7 @@
 
     /**
      * Normalize a specific DOM Range.
+     * @return {!Object} fixed normalized range
      */
     _normalizeRange(domRange) {
       const range = GrRangeNormalizer.normalize(domRange);
@@ -195,12 +201,12 @@
      *
      * @param {Node} node td.content child
      * @param {number} offset offset within node
-     * @return {{
+     * @return {({
      *   node: Node,
      *   side: string,
      *   line: Number,
      *   column: Number
-     * }}
+     * }|undefined)}
      */
     _normalizeSelectionSide(node, offset) {
       let column;
@@ -251,6 +257,7 @@
         return;
       }
       const domRange = window.getSelection().getRangeAt(0);
+      /** @type {?} */
       const start = normalizedRange.start;
       if (!start) {
         return;
@@ -280,7 +287,9 @@
       if (start.line === end.line) {
         actionBox.placeAbove(domRange);
       } else if (start.node instanceof Text) {
-        actionBox.placeAbove(start.node.splitText(start.column));
+        if (start.column) {
+          actionBox.placeAbove(start.node.splitText(start.column));
+        }
         start.node.parentElement.normalize(); // Undo splitText from above.
       } else if (start.node.classList.contains('content') &&
                  start.node.firstChild) {
@@ -325,7 +334,7 @@
      * Traverse Element from right to left, call callback for each node.
      * Stops if callback returns true.
      *
-     * @param {!Node} startNode
+     * @param {!Element} startNode
      * @param {function(Node):boolean} callback
      * @param {Object=} opt_flags If flags.left is true, traverse left.
      */
@@ -350,7 +359,7 @@
      * Get length of a node. If the node is a content node, then only give the
      * length of its .contentText child.
      *
-     * @param {!Node} node
+     * @param {?Element} node this is sometimes passed as null.
      * @return {number}
      */
     _getLength(node) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-range-normalizer.js b/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-range-normalizer.js
index 0b0131e..1ea5037 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-range-normalizer.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-highlight/gr-range-normalizer.js
@@ -27,8 +27,8 @@
      * highlighting, the containers are remapped to the .contentText divs that
      * contain the entire line of code.
      *
-     * @param {Object} range - the standard DOM selector range.
-     * @return {Object} A modified version of the range that correctly accounts
+     * @param {!Object} range - the standard DOM selector range.
+     * @return {!Object} A modified version of the range that correctly accounts
      *     for syntax highlighting.
      */
     normalize(range) {
@@ -94,8 +94,8 @@
     /**
      * The DOM API textContent.length calculation is broken when the text
      * contains Unicode. See https://mathiasbynens.be/notes/javascript-unicode .
-     * @param {Text} A text node.
-     * @return {Number} The length of the text.
+     * @param {text} node A text node.
+     * @return {number} The length of the text.
      */
     _getLength(node) {
       return node.textContent.replace(REGEX_ASTRAL_SYMBOL, '_').length;
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js b/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js
index 20833d0..f5944c3 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js
@@ -32,6 +32,7 @@
         reflectToAttribute: true,
       },
 
+      /** @type {?} */
       _newPrefs: Object,
       _newLocalPrefs: Object,
     },
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js b/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js
index 07b8429..bca6bea 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js
@@ -77,6 +77,7 @@
         value: 64,
       },
 
+      /** @type {number|undefined} */
       _nextStepHandle: Number,
       _isScrolling: Boolean,
     },
@@ -225,14 +226,14 @@
     /**
      * Take rows of a shared diff section and produce an array of corresponding
      * (potentially collapsed) groups.
-     * @param {Array<String>} rows
-     * @param {Number} context
-     * @param {Number} startLineNumLeft
-     * @param {Number} startLineNumRight
-     * @param {String} opt_sectionEnd String representing whether this is the
+     * @param {!Array<string>} rows
+     * @param {number} context
+     * @param {number} startLineNumLeft
+     * @param {number} startLineNumRight
+     * @param {?string=} opt_sectionEnd String representing whether this is the
      *     first section or the last section or neither. Use the values 'first',
      *     'last' and null respectively.
-     * @return {Array<GrDiffGroup>}
+     * @return {!Array<!Object>} Array of GrDiffGroup
      */
     _sharedGroupsFromRows(rows, context, startLineNumLeft,
         startLineNumRight, opt_sectionEnd) {
@@ -288,11 +289,11 @@
     /**
      * Take the rows of a delta diff section and produce the corresponding
      * group.
-     * @param {Array<String>} rowsAdded
-     * @param {Array<String>} rowsRemoved
-     * @param {Number} startLineNumLeft
-     * @param {Number} startLineNumRight
-     * @return {GrDiffGroup}
+     * @param {!Array<string>} rowsAdded
+     * @param {!Array<string>} rowsRemoved
+     * @param {number} startLineNumLeft
+     * @param {number} startLineNumRight
+     * @return {!Object} (Gr-Diff-Group)
      */
     _deltaGroupFromRows(rowsAdded, rowsRemoved, startLineNumLeft,
         startLineNumRight, highlights) {
@@ -309,7 +310,7 @@
     },
 
     /**
-     * @return {Array<GrDiffLine>}
+     * @return {!Array<!Object>} Array of GrDiffLines
      */
     _deltaLinesFromRows(lineType, rows, startLineNum,
         opt_highlights) {
@@ -348,8 +349,8 @@
      * In order to show comments out of the bounds of the selected context,
      * treat them as separate chunks within the model so that the content (and
      * context surrounding it) renders correctly.
-     * @param {Object} content The diff content object.
-     * @return {Object} A new diff content object with regions split up.
+     * @param {?} content The diff content object. (has to be iterable)
+     * @return {!Object} A new diff content object with regions split up.
      */
     _splitCommonGroupsWithComments(content) {
       const result = [];
@@ -492,7 +493,7 @@
      * If a group is an addition or a removal, break it down into smaller groups
      * of that type using the MAX_GROUP_SIZE. If the group is a shared section
      * or a delta it is returned as the single element of the result array.
-     * @param {!Object} A raw chunk from a diff response.
+     * @param {!Object} group A raw chunk from a diff response.
      * @return {!Array<!Array<!Object>>}
      */
     _breakdownGroup(group) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js b/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js
index ecddba2..3280b68 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js
@@ -31,6 +31,7 @@
 
     properties: {
       diff: Object,
+      /** @type {?Object} */
       _cachedDiffBuilder: Object,
       _linesCache: {
         type: Object,
@@ -144,14 +145,14 @@
      * true, it returns only the text of comments within the selection.
      * Otherwise it returns the text of the selected diff region.
      *
-     * @param {!string} The side that is selected.
-     * @param {boolean} Whether or not a comment is selected.
+     * @param {!string} side The side that is selected.
+     * @param {boolean} commentSelected Whether or not a comment is selected.
      * @return {string} The selected text.
      */
     _getSelectedText(side, commentSelected) {
       const sel = window.getSelection();
       if (sel.rangeCount != 1) {
-        return; // No multi-select support yet.
+        return ''; // No multi-select support yet.
       }
       if (commentSelected) {
         return this._getCommentLines(sel, side);
@@ -170,10 +171,10 @@
     /**
      * Query the diff object for the selected lines.
      *
-     * @param {int} startLineNum
-     * @param {int} startOffset
-     * @param {int} endLineNum
-     * @param {int} endOffset
+     * @param {number} startLineNum
+     * @param {number} startOffset
+     * @param {number} endLineNum
+     * @param {number} endOffset
      * @param {!string} side The side that is currently selected.
      * @return {string} The selected diff text.
      */
@@ -192,7 +193,7 @@
      * Query the diff object for the lines from a particular side.
      *
      * @param {!string} side The side that is currently selected.
-     * @return {Array.string} An array of strings indexed by line number.
+     * @return {!Array<string>} An array of strings indexed by line number.
      */
     _getDiffLines(side) {
       if (this._linesCache[side]) {
@@ -254,9 +255,9 @@
      * of the text content within that selection.
      * Using a domNode that isn't in the selection returns an empty string.
      *
-     * @param {Element} domNode The root DOM node.
-     * @param {Selection} sel The selection.
-     * @param {Range} range The normalized selection range.
+     * @param {!Node} domNode The root DOM node.
+     * @param {!Selection} sel The selection.
+     * @param {!Range} range The normalized selection range.
      * @return {string} The text within the selection.
      */
     _getTextContentForRange(domNode, sel, range) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index c12f700..5ec81e5 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -55,6 +55,9 @@
         type: Object,
         value() { return document.body; },
       },
+      /**
+       * @type {{ diffMode: (string|undefined) }}
+       */
       changeViewState: {
         type: Object,
         notify: true,
@@ -63,6 +66,13 @@
       },
 
       _patchRange: Object,
+      /**
+       * @type {{
+       *  subject: string,
+       *  project: string,
+       *  revisions: string,
+       * }}
+       */
       _change: Object,
       _changeNum: String,
       _diff: Object,
@@ -400,7 +410,7 @@
 
     /**
      * @param {?string} path The path of the current file being shown.
-     * @param {Array.<string>} fileList The list of files in this change and
+     * @param {!Array<string>} fileList The list of files in this change and
      *     patch range.
      * @param {number} direction Either 1 (next file) or -1 (prev file).
      * @param {(number|boolean)} opt_noUp Whether to return to the change view
@@ -433,12 +443,12 @@
      *   * null - When no navigation is possible for the given direction.
      *
      * @param {?string} path The path of the current file being shown.
-     * @param {Array.<string>} fileList The list of files in this change and
+     * @param {!Array<string>} fileList The list of files in this change and
      *     patch range.
      * @param {number} direction Either 1 (next file) or -1 (prev file).
-     * @param {(number|boolean)} opt_noUp Whether to return to the change view
+     * @param {?number|boolean=} opt_noUp Whether to return to the change view
      *     when advancing the file goes outside the bounds of fileList.
-     * @return {Object}
+     * @return {?Object}
      */
     _getNavLinkPath(path, fileList, direction, opt_noUp) {
       if (!path || fileList.length === 0) { return null; }
@@ -589,6 +599,10 @@
      * When the latest patch of the change is selected (and there is no base
      * patch) then the patch range need not appear in the URL. Return a patch
      * range object with undefined values when a range is not needed.
+     *
+     * @param {!Object} patchRange
+     * @param {!Object} revisions
+     * @return {!Object}
      */
     _getChangeUrlRange(patchRange, revisions) {
       let patchNum = undefined;
@@ -702,7 +716,7 @@
      *
      * Use side-by-side if the user is not logged in.
      *
-     * @return {String}
+     * @return {string}
      */
     _getDiffViewMode() {
       if (this.changeViewState.diffMode) {
@@ -721,7 +735,7 @@
 
     _onLineSelected(e, detail) {
       this.$.cursor.moveToLineNumber(detail.number, detail.side);
-      history.replaceState(null, null, '#' + this.$.cursor.getAddress());
+      history.replaceState(null, '', '#' + this.$.cursor.getAddress());
     },
 
     _computeDownloadLink(changeNum, patchRange, path) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
index 728a766..0f30171 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
@@ -106,7 +106,9 @@
         type: String,
         value: '',
       },
+      /** @type {?Object} */
       _baseImage: Object,
+      /** @type {?Object} */
       _revisionImage: Object,
 
       /**
@@ -114,6 +116,8 @@
        * been bypassed. If the value is null, then the safety has not been
        * bypassed. If the value is a number, then that number represents the
        * context preference to use when rendering the bypassed diff.
+       *
+       * @type (number|null)
        */
       _safetyBypass: {
         type: Number,
@@ -147,6 +151,7 @@
       }
     },
 
+    /** @return {!Promise} */
     reload() {
       this.$.diffBuilder.cancel();
       this._safetyBypass = null;
@@ -168,6 +173,7 @@
       });
     },
 
+    /** @return {!Array<!HTMLElement>} */
     getCursorStops() {
       if (this.hidden && this.noAutoRender) {
         return [];
@@ -176,6 +182,7 @@
       return Polymer.dom(this.root).querySelectorAll('.diff-row');
     },
 
+    /** @return {boolean} */
     isRangeSelected() {
       return this.$.highlights.isRangeSelected();
     },
@@ -184,15 +191,18 @@
       this.toggleClass('no-left');
     },
 
+    /** @return {boolean}} */
     _canRender() {
-      return this.changeNum && this.patchRange && this.path &&
+      return !!this.changeNum && !!this.patchRange && !!this.path &&
           !this.noAutoRender;
     },
 
+    /** @return {!Array<!HTMLElement>} */
     _getCommentThreads() {
       return Polymer.dom(this.root).querySelectorAll('gr-diff-comment-thread');
     },
 
+    /** @return {string} */
     _computeContainerClass(loggedIn, viewMode, displayLine) {
       const classes = ['diffContainer'];
       switch (viewMode) {
@@ -263,7 +273,7 @@
       const side = e.detail.side;
       const lineNum = range.endLine;
       const lineEl = this.$.diffBuilder.getLineElByNumber(lineNum, side);
-      this._isValidElForComment(el).then(valid => {
+      this._isValidElForComment(lineEl).then(valid => {
         if (!valid) { return; }
 
         this._createComment(lineEl, lineNum, side, range);
@@ -288,6 +298,12 @@
       });
     },
 
+    /**
+     * @param {!Object} lineEl
+     * @param {number=} opt_lineNum
+     * @param {string=} opt_side
+     * @param {!Object=} opt_range
+     */
     _createComment(lineEl, opt_lineNum, opt_side, opt_range) {
       const contentText = this.$.diffBuilder.getContentByLineEl(lineEl);
       const contentEl = contentText.parentElement;
@@ -309,14 +325,21 @@
       return contentEl.querySelector('gr-diff-comment-thread-group');
     },
 
+    /**
+     * @param {!Object} contentEl
+     * @param {number} patchNum
+     * @param {string} commentSide
+     * @param {boolean} isOnParent
+     * @param {!Object=} opt_range
+     */
     _getOrCreateThreadAtLineRange(contentEl, patchNum, commentSide,
-        isOnParent, range) {
-      const rangeToCheck = range ?
+        isOnParent, opt_range) {
+      const rangeToCheck = opt_range ?
           'range-' +
-          range.startLine + '-' +
-          range.startChar + '-' +
-          range.endLine + '-' +
-          range.endChar + '-' +
+          opt_range.startLine + '-' +
+          opt_range.startChar + '-' +
+          opt_range.endLine + '-' +
+          opt_range.endChar + '-' +
           commentSide : 'line-' + commentSide;
 
       // Check if thread group exists.
@@ -338,6 +361,7 @@
       return threadEl;
     },
 
+    /** @return {number} */
     _getPatchNumByLineAndContent(lineEl, contentEl) {
       let patchNum = this.patchRange.patchNum;
       if ((lineEl.classList.contains(DiffSide.LEFT) ||
@@ -348,6 +372,7 @@
       return patchNum;
     },
 
+    /** @return {boolean} */
     _getIsParentCommentByLineAndContent(lineEl, contentEl) {
       let isOnParent = false;
       if ((lineEl.classList.contains(DiffSide.LEFT) ||
@@ -358,6 +383,7 @@
       return isOnParent;
     },
 
+    /** @return {string} */
     _getCommentSideByLineAndContent(lineEl, contentEl) {
       let side = 'right';
       if (lineEl.classList.contains(DiffSide.LEFT) ||
@@ -374,7 +400,7 @@
 
     _handleCommentDiscard(e) {
       const comment = e.detail.comment;
-      this._removeComment(comment, e.detail.patchNum);
+      this._removeComment(comment);
     },
 
     _removeComment(comment) {
@@ -389,6 +415,12 @@
       this.set(['comments', side, idx], comment);
     },
 
+    /**
+     * Closure annotation for Polymer.prototype.push is off. Submitted PR:
+     * https://github.com/Polymer/polymer/pull/4776
+     * but for not supressing annotations.
+     *
+     * @suppress {checkTypes} */
     _handleCommentUpdate(e) {
       const comment = e.detail.comment;
       const side = e.detail.comment.__commentSide;
@@ -413,6 +445,7 @@
       }
     },
 
+    /** @return {number} */
     _findCommentIndex(comment, side) {
       if (!comment.id || !this.comments[side]) {
         return -1;
@@ -422,6 +455,7 @@
       });
     },
 
+    /** @return {number} */
     _findDraftIndex(comment, side) {
       if (!comment.__draftID || !this.comments[side]) {
         return -1;
@@ -517,6 +551,7 @@
       this.fire('page-error', {response});
     },
 
+    /** @return {!Promise<!Object>} */
     _getDiff() {
       return this.$.restAPI.getDiff(
           this.changeNum,
@@ -532,10 +567,12 @@
           });
     },
 
+    /** @return {!Promise} */
     _getLoggedIn() {
       return this.$.restAPI.getLoggedIn();
     },
 
+    /** @return {boolean} */
     _computeIsImageDiff() {
       if (!this._diff) { return false; }
 
@@ -547,6 +584,7 @@
       return this._diff.binary && (isA || isB);
     },
 
+    /** @return {!Promise} */
     _loadDiffAssets() {
       if (this.isImageDiff) {
         return this._getImages().then(images => {
@@ -560,6 +598,7 @@
       }
     },
 
+    /** @return {!Promise} */
     _getImages() {
       return this.$.restAPI.getImagesForDiff(this.changeNum, this._diff,
           this.patchRange);
@@ -572,6 +611,7 @@
       }
     },
 
+    /** @return {!Array} */
     _computeDiffHeaderItems(diffInfoRecord) {
       const diffInfo = diffInfoRecord.base;
       if (!diffInfo || !diffInfo.diff_header || diffInfo.binary) { return []; }
@@ -583,6 +623,7 @@
       });
     },
 
+    /** @return {boolean} */
     _computeDiffHeaderHidden(items) {
       return items.length === 0;
     },
@@ -591,7 +632,7 @@
      * The number of lines in the diff. For delta chunks that are different
      * sizes on the left and the right, the longer side is used.
      * @param {!Object} diff
-     * @return {Number}
+     * @return {number}
      */
     _diffLength(diff) {
       return diff.content.reduce((sum, sec) => {
@@ -616,6 +657,7 @@
       this._renderDiffTable();
     },
 
+    /** @return {string} */
     _computeWarningClass(showWarning) {
       return showWarning ? 'warn' : '';
     },
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
index 9a4000f..d6052de 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
@@ -23,6 +23,7 @@
     properties: {
       availablePatches: Array,
       changeNum: String,
+      /** @type {{ meta_a: !Array, meta_b: !Array}} */
       filesWeblinks: Object,
       path: String,
       patchRange: {
diff --git a/polygerrit-ui/app/elements/diff/gr-ranged-comment-layer/gr-ranged-comment-layer.js b/polygerrit-ui/app/elements/diff/gr-ranged-comment-layer/gr-ranged-comment-layer.js
index aa55414..3de18be 100644
--- a/polygerrit-ui/app/elements/diff/gr-ranged-comment-layer/gr-ranged-comment-layer.js
+++ b/polygerrit-ui/app/elements/diff/gr-ranged-comment-layer/gr-ranged-comment-layer.js
@@ -43,9 +43,9 @@
 
     /**
      * Layer method to add annotations to a line.
-     * @param {HTMLElement} el The DIV.contentText element to apply the
+     * @param {!HTMLElement} el The DIV.contentText element to apply the
      *     annotation to.
-     * @param {GrDiffLine} line The line object.
+     * @param {!Object} line The line object. (GrDiffLine)
      */
     annotate(el, line) {
       let ranges = [];
@@ -79,9 +79,9 @@
 
     /**
      * Notify Layer listeners of changes to annotations.
-     * @param {Number} start The line where the update starts.
-     * @param {Number} end The line where the update ends.
-     * @param {String} side The side of the update. ('left' or 'right')
+     * @param {number} start The line where the update starts.
+     * @param {number} end The line where the update ends.
+     * @param {string} side The side of the update. ('left' or 'right')
      */
     _notifyUpdateRange(start, end, side) {
       for (const listener of this._listeners) {
@@ -133,8 +133,9 @@
      * Take a list of comments and return a sparse list mapping line numbers to
      * partial ranges. Uses an end-character-index of -1 to indicate the end of
      * the line.
-     * @param {Array<Object>} commentList The list of comments.
-     * @return {Object} The sparse list.
+     * @param {?} commentList The list of comments.
+     *    Getting this param to match closure requirements caused problems.
+     * @return {!Object} The sparse list.
      */
     _computeCommentMap(commentList) {
       const result = {};
diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
index 2c1167c..91e6287 100644
--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
+++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
@@ -114,6 +114,7 @@
         type: Array,
         value() { return []; },
       },
+      /** @type {?number} */
       _processHandle: Number,
       _hljs: Object,
     },
@@ -126,7 +127,7 @@
      * Annotation layer method to add syntax annotations to the given element
      * for the given line.
      * @param {!HTMLElement} el
-     * @param {!GrDiffLine} line
+     * @param {!Object} line (GrDiffLine)
      */
     annotate(el, line) {
       if (!this.enabled) { return; }