Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
make some type annotations explicit
Browse files Browse the repository at this point in the history
This CL adds an explicit type to some code that lacked one.
The intent is to preserve the existing type, but make it explicit.
(Note that in the case of function return types, Closure sometimes
infers a `{?}` return type, so this CL may tighten some of these.)
RELNOTES: n/a
PiperOrigin-RevId: 367694623
  • Loading branch information
evmar authored and kjin committed Apr 14, 2021
1 parent 7d07947 commit 7d1c8f1
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 5 deletions.
5 changes: 4 additions & 1 deletion closure/goog/asserts/asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ goog.asserts.AssertionError = function(messagePattern, messageArgs) {
goog.inherits(goog.asserts.AssertionError, goog.debug.Error);


/** @override */
/** @override @type {string} */
goog.asserts.AssertionError.prototype.name = 'AssertionError';


/**
* The default error handler.
* @param {!goog.asserts.AssertionError} e The exception to be handled.
* @return {void}
*/
goog.asserts.DEFAULT_ERROR_HANDLER = function(e) {
'use strict';
Expand Down Expand Up @@ -155,6 +156,7 @@ goog.asserts.doAssertFailure_ = function(
* assertion failures, for example by turning all assertion failures into log
* messages.
* @param {function(!goog.asserts.AssertionError)} errorHandler
* @return {void}
*/
goog.asserts.setErrorHandler = function(errorHandler) {
'use strict';
Expand Down Expand Up @@ -234,6 +236,7 @@ goog.asserts.assertExists = function(value, opt_message, var_args) {
*
* @param {string=} opt_message Error message in case of failure.
* @param {...*} var_args The items to substitute into the failure message.
* @return {void}
* @throws {goog.asserts.AssertionError} Failure.
* @closurePrimitive {asserts.fail}
*/
Expand Down
2 changes: 1 addition & 1 deletion closure/goog/debug/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function DebugError(msg = undefined, cause = undefined) {
goog.inherits(DebugError, Error);


/** @override */
/** @override @type {string} */
DebugError.prototype.name = 'CustomError';


Expand Down
5 changes: 5 additions & 0 deletions closure/goog/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ goog.dom.append = function(parent, var_args) {
/**
* Removes all the child nodes on a DOM node.
* @param {Node} node Node to remove children from.
* @return {void}
*/
goog.dom.removeChildren = function(node) {
'use strict';
Expand Down Expand Up @@ -1275,6 +1276,7 @@ goog.dom.insertSiblingBefore = function(newNode, refNode) {
* sibling). If the reference node has no parent, then does nothing.
* @param {Node} newNode Node to insert.
* @param {Node} refNode Reference node to insert after.
* @return {void}
*/
goog.dom.insertSiblingAfter = function(newNode, refNode) {
'use strict';
Expand All @@ -1295,6 +1297,7 @@ goog.dom.insertSiblingAfter = function(newNode, refNode) {
* @param {Node} child The element to insert.
* @param {number} index The index at which to insert the new child node. Must
* not be negative.
* @return {void}
*/
goog.dom.insertChildAt = function(parent, child, index) {
'use strict';
Expand Down Expand Up @@ -1867,6 +1870,7 @@ goog.dom.getFrameContentWindow = function(frame) {
* Sets the text content of a node, with cross-browser support.
* @param {Node} node The node to change the text content of.
* @param {string|number} text The value that should replace the node's content.
* @return {void}
*/
goog.dom.setTextContent = function(node, text) {
'use strict';
Expand Down Expand Up @@ -2106,6 +2110,7 @@ goog.dom.isFocusableTabIndex = function(element) {
* @param {Element} element Element whose tab index is to be changed.
* @param {boolean} enable Whether to set or remove a tab index on the element
* that supports keyboard focus.
* @return {void}
*/
goog.dom.setFocusableTabIndex = function(element, enable) {
'use strict';
Expand Down
19 changes: 19 additions & 0 deletions closure/goog/dom/safe.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ goog.dom.safe.setOuterHtml = function(elem, html) {
* @param {!Element} form The form element whose action property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setFormElementAction = function(form, url) {
Expand Down Expand Up @@ -243,6 +244,7 @@ goog.dom.safe.setFormElementAction = function(form, url) {
* @param {!Element} button The button element whose action property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setButtonFormAction = function(button, url) {
Expand Down Expand Up @@ -274,6 +276,7 @@ goog.dom.safe.setButtonFormAction = function(button, url) {
* @param {!Element} input The input element whose action property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setInputFormAction = function(input, url) {
Expand All @@ -294,6 +297,7 @@ goog.dom.safe.setInputFormAction = function(input, url) {
* SafeStyle object.
* @param {!Element} elem
* @param {!goog.html.SafeStyle} style
* @return {void}
*/
goog.dom.safe.setStyle = function(elem, style) {
'use strict';
Expand All @@ -305,6 +309,7 @@ goog.dom.safe.setStyle = function(elem, style) {
* Writes known-safe HTML to a document.
* @param {!Document} doc The document to be written to.
* @param {!goog.html.SafeHtml} html The known-safe HTML to assign.
* @return {void}
*/
goog.dom.safe.documentWrite = function(doc, html) {
'use strict';
Expand All @@ -329,6 +334,7 @@ goog.dom.safe.documentWrite = function(doc, html) {
* @param {!HTMLAnchorElement} anchor The anchor element whose href property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setAnchorHref = function(anchor, url) {
Expand All @@ -355,6 +361,7 @@ goog.dom.safe.setAnchorHref = function(anchor, url) {
* @param {!HTMLImageElement} imageElement The image element whose src property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setImageSrc = function(imageElement, url) {
Expand All @@ -381,6 +388,7 @@ goog.dom.safe.setImageSrc = function(imageElement, url) {
* @param {!HTMLAudioElement} audioElement The audio element whose src property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setAudioSrc = function(audioElement, url) {
Expand All @@ -407,6 +415,7 @@ goog.dom.safe.setAudioSrc = function(audioElement, url) {
* @param {!HTMLVideoElement} videoElement The video element whose src property
* is to be assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.setVideoSrc = function(videoElement, url) {
Expand Down Expand Up @@ -457,6 +466,7 @@ goog.dom.safe.setEmbedSrc = function(embed, url) {
* @param {!HTMLFrameElement} frame The frame element whose src property
* is to be assigned to.
* @param {!goog.html.TrustedResourceUrl} url The URL to assign.
* @return {void}
*/
goog.dom.safe.setFrameSrc = function(frame, url) {
'use strict';
Expand All @@ -478,6 +488,7 @@ goog.dom.safe.setFrameSrc = function(frame, url) {
* @param {!HTMLIFrameElement} iframe The iframe element whose src property
* is to be assigned to.
* @param {!goog.html.TrustedResourceUrl} url The URL to assign.
* @return {void}
*/
goog.dom.safe.setIframeSrc = function(iframe, url) {
'use strict';
Expand All @@ -498,6 +509,7 @@ goog.dom.safe.setIframeSrc = function(iframe, url) {
* @param {!HTMLIFrameElement} iframe The iframe element whose srcdoc property
* is to be assigned to.
* @param {!goog.html.SafeHtml} html The HTML to assign.
* @return {void}
*/
goog.dom.safe.setIframeSrcdoc = function(iframe, html) {
'use strict';
Expand Down Expand Up @@ -527,6 +539,7 @@ goog.dom.safe.setIframeSrcdoc = function(iframe, html) {
* value assigned to rel contains "stylesheet". A string value is
* sanitized with goog.html.SafeUrl.sanitize.
* @param {string} rel The value to assign to the rel property.
* @return {void}
* @throws {Error} if rel contains "stylesheet" and url is not a
* TrustedResourceUrl
* @see goog.html.SafeUrl#sanitize
Expand Down Expand Up @@ -565,6 +578,7 @@ goog.dom.safe.setLinkHrefAndRel = function(link, url, rel) {
* @param {!HTMLObjectElement} object The object element whose data property
* is to be assigned to.
* @param {!goog.html.TrustedResourceUrl} url The URL to assign.
* @return {void}
*/
goog.dom.safe.setObjectData = function(object, url) {
'use strict';
Expand All @@ -586,6 +600,7 @@ goog.dom.safe.setObjectData = function(object, url) {
* @param {!HTMLScriptElement} script The script element whose src property
* is to be assigned to.
* @param {!goog.html.TrustedResourceUrl} url The URL to assign.
* @return {void}
*/
goog.dom.safe.setScriptSrc = function(script, url) {
'use strict';
Expand All @@ -608,6 +623,7 @@ goog.dom.safe.setScriptSrc = function(script, url) {
* @param {!HTMLScriptElement} script The script element whose content is being
* set.
* @param {!goog.html.SafeScript} content The content to assign.
* @return {void}
*/
goog.dom.safe.setScriptContent = function(script, content) {
'use strict';
Expand Down Expand Up @@ -650,6 +666,7 @@ goog.dom.safe.setNonceForScriptElement_ = function(script) {
* @param {!Location} loc The Location object whose href property is to be
* assigned to.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
Expand Down Expand Up @@ -685,6 +702,7 @@ goog.dom.safe.setLocationHref = function(loc, url) {
*
* @param {!Location} loc The Location object which is to be assigned.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.assignLocation = function(loc, url) {
Expand Down Expand Up @@ -717,6 +735,7 @@ goog.dom.safe.assignLocation = function(loc, url) {
*
* @param {!Location} loc The Location object which is to be replaced.
* @param {string|!goog.html.SafeUrl} url The URL to assign.
* @return {void}
* @see goog.html.SafeUrl#sanitize
*/
goog.dom.safe.replaceLocation = function(loc, url) {
Expand Down
4 changes: 4 additions & 0 deletions closure/goog/events/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ goog.events.Event.prototype.hasPropagationStopped = function() {

/**
* Stops event propagation.
* @return {void}
*/
goog.events.Event.prototype.stopPropagation = function() {
'use strict';
Expand All @@ -90,6 +91,7 @@ goog.events.Event.prototype.stopPropagation = function() {

/**
* Prevents the default action, for example a link redirecting to a url.
* @return {void}
*/
goog.events.Event.prototype.preventDefault = function() {
'use strict';
Expand All @@ -102,6 +104,7 @@ goog.events.Event.prototype.preventDefault = function() {
* `e.stopPropagation()`, but can be used as the callback argument of
* {@link goog.events.listen} without declaring another function.
* @param {!goog.events.Event} e An event.
* @return {void}
*/
goog.events.Event.stopPropagation = function(e) {
'use strict';
Expand All @@ -114,6 +117,7 @@ goog.events.Event.stopPropagation = function(e) {
* `e.preventDefault()`, but can be used as the callback argument of
* {@link goog.events.listen} without declaring another function.
* @param {!goog.events.Event} e An event.
* @return {void}
*/
goog.events.Event.preventDefault = function(e) {
'use strict';
Expand Down
1 change: 1 addition & 0 deletions closure/goog/events/eventid.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ goog.events.EventId = function(eventId) {

/**
* @override
* @return {string}
*/
goog.events.EventId.prototype.toString = function() {
'use strict';
Expand Down
2 changes: 2 additions & 0 deletions closure/goog/fs/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ goog.fs.url.createObjectUrl = function(obj) {
* Throws an error if the browser does not support Object Urls.
*
* @param {string} url The URL to revoke.
* @return {void}
*/
goog.fs.url.revokeObjectUrl = function(url) {
'use strict';
Expand All @@ -52,6 +53,7 @@ goog.fs.url.UrlObject_.prototype.createObjectURL = function(arg) {};

/**
* @param {string} s
* @return {void}
*/
goog.fs.url.UrlObject_.prototype.revokeObjectURL = function(s) {};

Expand Down
3 changes: 2 additions & 1 deletion closure/goog/html/safehtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ goog.html.SafeHtml.prototype.getDirection = function() {

/**
* @override
* @const
* @const {boolean}
*/
goog.html.SafeHtml.prototype.implementsGoogStringTypedString = true;

Expand Down Expand Up @@ -448,6 +448,7 @@ goog.html.SafeHtml.create = function(tagName, opt_attributes, opt_content) {
* E.g. STRONG is fine but SCRIPT throws because it changes context. See
* goog.html.SafeHtml.create for an explanation of allowed tags.
* @param {string} tagName
* @return {void}
* @throws {!Error} If invalid tag name is provided.
* @package
*/
Expand Down
2 changes: 1 addition & 1 deletion closure/goog/html/safestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ goog.html.SafeStyle = class {

/**
* @override
* @const
* @const {boolean}
*/
goog.html.SafeStyle.prototype.implementsGoogStringTypedString = true;

Expand Down
4 changes: 3 additions & 1 deletion closure/goog/html/safeurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ goog.html.SafeUrl.prototype.getTypedStringValue = function() {

/**
* @override
* @const
* @const {boolean}
*/
goog.html.SafeUrl.prototype.implementsGoogI18nBidiDirectionalString = true;


/**
* Returns this URLs directionality, which is always `LTR`.
* @override
* @return {!goog.i18n.bidi.Dir}
*/
goog.html.SafeUrl.prototype.getDirection = function() {
'use strict';
Expand Down Expand Up @@ -287,6 +288,7 @@ goog.html.SafeUrl.fromBlob = function(blob) {
/**
* Revokes an object URL created for a safe URL created {@link fromBlob()}.
* @param {!goog.html.SafeUrl} safeUrl SafeUrl wrapping a blob object.
* @return {void}
*/
goog.html.SafeUrl.revokeObjectUrl = function(safeUrl) {
'use strict';
Expand Down
1 change: 1 addition & 0 deletions closure/goog/html/trustedresourceurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ goog.html.TrustedResourceUrl.prototype.implementsGoogI18nBidiDirectionalString =
/**
* Returns this URLs directionality, which is always `LTR`.
* @override
* @return {!goog.i18n.bidi.Dir}
*/
goog.html.TrustedResourceUrl.prototype.getDirection = function() {
'use strict';
Expand Down
2 changes: 2 additions & 0 deletions closure/goog/i18n/bidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ goog.i18n.bidi.detectRtlDirectionality = function(str, opt_isHtml) {
* 2. A number (positive = LRT, negative = RTL, 0 = neutral).
* 3. A boolean (true = RTL, false = LTR).
* 4. A null for unknown directionality.
* @return {void}
*/
goog.i18n.bidi.setElementDirAndAlign = function(element, dir) {
'use strict';
Expand All @@ -889,6 +890,7 @@ goog.i18n.bidi.setElementDirAndAlign = function(element, dir) {
* Sets element dir based on estimated directionality of the given text.
* @param {!Element} element
* @param {string} text
* @return {void}
*/
goog.i18n.bidi.setElementDirByTextDirectionality = function(element, text) {
'use strict';
Expand Down
1 change: 1 addition & 0 deletions closure/goog/labs/useragent/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ goog.labs.userAgent.util.userAgent_ =
* navigator.userAgent object by setting this string. Set to null to use the
* browser object instead.
* @param {?string=} opt_userAgent The User-Agent override.
* @return {void}
*/
goog.labs.userAgent.util.setUserAgent = function(opt_userAgent) {
'use strict';
Expand Down
Loading

0 comments on commit 7d1c8f1

Please sign in to comment.