Skip to content

Commit

Permalink
♻️ Types: opt for null shorthand (ampproject#34233)
Browse files Browse the repository at this point in the history
* types: shorthand for |null

* a few more

* fix test
  • Loading branch information
samouri authored and rochapablo committed Aug 30, 2021
1 parent 1e32c94 commit f8fdea2
Show file tree
Hide file tree
Showing 56 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion ads/google/a4a/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function makeCorrelator(pageViewId, opt_clientId) {
/**
* Collect additional dimensions for the brdim parameter.
* @param {!Window} win The window for which we read the browser dimensions.
* @param {{width: number, height: number}|null} viewportSize
* @param {?{width: number, height: number}} viewportSize
* @return {string}
* @visibleForTesting
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/**
* @protected {!Object<string, !ChildDef>|null}
* @protected {?Object<string, !ChildDef>}
*/
foo().bar;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/**
* @protected {!Object<string, !ChildDef>|null}
* @protected {?Object<string, !ChildDef>}
*/
foo().bar;

Expand Down
2 changes: 1 addition & 1 deletion build-system/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function buildRuntime(opt_compiled = false) {
/**
* Extracts and validates the config for the given experiment.
* @param {string} experiment
* @return {Object|null}
* @return {?Object}
*/
function getExperimentConfig(experiment) {
const config = experimentsConfig[experiment];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
/**
* @param {Array<T>} array
* @param {T} item
* @return {T|null}
* @return {?T}
*/
function findAfter(array, item) {
const index = array.indexOf(item);
Expand Down
2 changes: 1 addition & 1 deletion build-system/externs/amp.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ AmpElement.prototype.collapse = function () {};
let Signals = class {};
/**
* @param {string} unusedName
* @return {number|!Error|null}
* @return {?number|?Error}
*/
Signals.prototype.get = function (unusedName) {};

Expand Down
2 changes: 1 addition & 1 deletion build-system/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ function generateInfo(filePath) {

/**
* @param {string} encryptedDocumentKey
* @return {string|null}
* @return {?string}
*/
function decryptDocumentKey(encryptedDocumentKey) {
if (!encryptedDocumentKey) {
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/markdown-toc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function isolateCommentJson(maybeComment) {

/**
* @param {string} content
* @return {Promise<string|null>}
* @return {Promise<?string>}
*/
async function overrideToc(content) {
const headerMatch = content.match(headerRegexp);
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/performance/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const q3 = (array) => {
*
* @param {number} a
* @param {number} b
* @return {number|null} percentage change or null
* @return {?number} percentage change or null
*/
function percent(a, b) {
if (a === 0) {
Expand Down
18 changes: 9 additions & 9 deletions extensions/amp-access-poool/0.1/poool-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const AUTHORIZATION_TIMEOUT = 3000;
/**
* @typedef {{
* appId: string,
* pageType: (string),
* debug: (boolean|null),
* forceWidget: (string|null),
* loginButtonEnabled: (boolean),
* videoClient: (string|null),
* customSegment: (string|null),
* cookiesEnabled: (boolean),
* locale: (string|null),
* context: (string|null),
* pageType: string,
* debug: ?boolean,
* forceWidget: ?string,
* loginButtonEnabled: boolean,
* videoClient: ?string,
* customSegment: ?string,
* cookiesEnabled: boolean,
* locale: ?string,
* context: ?string,
* }}
*/
let PooolConfigDef;
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-access/0.1/access-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AccessVars {
* This is a restricted API.
*
* @param {string} unusedField
* @return {?Promise<*|null>}
* @return {?Promise<*>}
*/
getAuthdataField(unusedField) {}
}
2 changes: 1 addition & 1 deletion extensions/amp-accordion/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const generateRandomId = randomIdGenerator(100000);

/**
* @param {!AccordionDef.AccordionProps} props
* @param {{current: (!AccordionDef.AccordionApi|null)}} ref
* @param {{current: ?AccordionDef.AccordionApi}} ref
* @return {PreactDef.Renderable}
*/
function AccordionWithRef(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class AmpAdNetworkAdzerkImpl extends AmpA4A {
// TODO(wg-monetization): this header name has been deprecated elsewhere,
// and is never returned by dev server.
if (headers.get(AMP_TEMPLATED_CREATIVE_HEADER_NAME) !== 'amp-mustache') {
return /**@type {!Promise<(ArrayBuffer|null)>}*/ (Promise.resolve(null));
return /**@type {!Promise<?ArrayBuffer>}*/ (Promise.resolve(null));
}
// Shorthand for: reject promise if current promise chain is out of date.
const checkStillCurrent = this.verifyStillCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class SafeframeHostApi {
* Returns true if the given window matches the Safeframe's content window.
* Comparing to a null window will always return false.
*
* @param {Window|null} otherWindow
* @param {?Window} otherWindow
* @return {boolean}
*/
equalsSafeframeContentWindow(otherWindow) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-addthis/0.1/amp-addthis.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class AmpAddThis extends AMP.BaseElement {
/** @private {string} */
this.referrer_ = '';

/** @private {(?JsonObject<string, string>|null)} */
/** @private {?JsonObject<string, string>} */
this.shareConfig_ = null;

/** @private {(?JsonObject)} */
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class ScrollEventTracker extends EventTracker {
/** @private {!./analytics-root.AnalyticsRoot} root */
this.root_ = root;

/** @private {function(!Object)|null} */
/** @private {?function(!Object)} */
this.boundScrollHandler_ = null;
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {computedStyle} from '../../../src/style';

/**
* Returns the min opacity found amongst the element and its ancestors
* @param {!Element|null} el
* @param {?Element} el
* @return {number} minimum opacity value
*/
export function getMinOpacity(el) {
Expand Down Expand Up @@ -73,7 +73,7 @@ function getElementOpacity(el) {
/**
* Returns the node tree of the current element starting from
* the document root
* @param {!Element|null} el
* @param {?Element} el
* @return {Array} node list of the element's node tree
*/
function getElementNodeTree(el) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/scroll-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ScrollManager {
/** @const @private {!../../../src/service/mutator-interface.MutatorInterface} */
this.mutator_ = Services.mutatorForDoc(root.ampdoc);

/** @private {!UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.viewportOnChangedUnlistener_ = null;

/** @private {!Observable<!./scroll-manager.ScrollEventDef>} */
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-base-carousel/1.0/base-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const MIN_AUTO_ADVANCE_INTERVAL = 1000;

/**
* @param {!BaseCarouselDef.Props} props
* @param {{current: (!BaseCarouselDef.CarouselApi|null)}} ref
* @param {{current: ?BaseCarouselDef.CarouselApi}} ref
* @return {PreactDef.Renderable}
*/
function BaseCarouselWithRef(
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-base-carousel/1.0/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const RESET_SCROLL_REFERENCE_POINT_WAIT_MS = 200;

/**
* @param {!BaseCarouselDef.ScrollerProps} props
* @param {{current: (T|null)}} ref
* @param {{current: ?T}} ref
* @return {PreactDef.Renderable}
* @template T
*/
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-date-countdown/0.1/amp-date-countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class AmpDateCountdown extends AMP.BaseElement {
/** @private {string} */
this.biggestUnit_ = '';

/** @private {!Object|null} */
/** @private {?Object} */
this.localeWordList_ = null;

/** @private {?number} */
Expand Down Expand Up @@ -156,7 +156,7 @@ export class AmpDateCountdown extends AMP.BaseElement {
this.element.getAttribute('biggest-unit') || DEFAULT_BIGGEST_UNIT
).toUpperCase();

/** @private {!Object|null} */
/** @private {?Object} */
this.localeWordList_ = this.getLocaleWord_(this.locale_);

/** @private {boolean} */
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-facebook-comments/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const DEFAULT_TITLE = 'Facebook comments';

/**
* @param {!FacebookCommentsDef.Props} props
* @param {{current: (!FacebookCommentsDef.Api|null)}} ref
* @param {{current: ?FacebookCommentsDef.Api}} ref
* @return {PreactDef.Renderable}
*/
function FacebookCommentsWithRef(
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-form/0.1/form-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class FormValidator {

/**
* Tribool indicating last known validity of form.
* @private {boolean|null}
* @private {?boolean}
*/
this.formValidity_ = null;
}
Expand Down
42 changes: 21 additions & 21 deletions extensions/amp-image-slider/0.1/amp-image-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,53 @@ export class AmpImageSlider extends AMP.BaseElement {
/** @private {Document} */
this.doc_ = this.win.document;

/** @private {Element|null} */
/** @private {?Element} */
this.container_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.leftAmpImage_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.rightAmpImage_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.leftLabelWrapper_ = null;
/** @private {Element|null} */
/** @private {?Element} */
this.leftLabel_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.rightLabelWrapper_ = null;
/** @private {Element|null} */
/** @private {?Element} */
this.rightLabel_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.leftMask_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.rightMask_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.bar_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.barStick_ = null;

/** @private {Element|null} */
/** @private {?Element} */
this.hintLeftArrow_ = null;
/** @private {Element|null} */
/** @private {?Element} */
this.hintRightArrow_ = null;
/** @private {Element|null} */
/** @private {?Element} */
this.hintLeftBody_ = null;
/** @private {Element|null} */
/** @private {?Element} */
this.hintRightBody_ = null;

/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenMouseDown_ = null;
/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenMouseUp_ = null;
/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenMouseMove_ = null;
/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenKeyDown_ = null;

// Step size on keyboard action, 0.1 = 10%
Expand All @@ -98,7 +98,7 @@ export class AmpImageSlider extends AMP.BaseElement {
'disable-hint-reappear'
);

/** @private {Gestures|null} */
/** @private {?Gestures} */
this.gestures_ = null;

/** @private {boolean} */
Expand Down Expand Up @@ -509,7 +509,7 @@ export class AmpImageSlider extends AMP.BaseElement {

/**
* Unlisten a listener and clear. If null, does nothing
* @param {UnlistenDef|null} unlistenHandle
* @param {?UnlistenDef} unlistenHandle
* @private
*/
unlisten_(unlistenHandle) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-instagram/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MATCHES_MESSAGING_ORIGIN = (origin) =>

/**
* @param {!InstagramDef.Props} props
* @param {{current: (!InstagramDef.Api|null)}} ref
* @param {{current: ?InstagramDef.Api}} ref
* @return {PreactDef.Renderable}
*/
function InstagramWithRef(
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-jwplayer/0.1/amp-jwplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class AmpJWPlayer extends AMP.BaseElement {
/** @private {number} */
this.currentTime_ = 0;

/** @private {Array<(Array<number>|null)>} */
/** @private {Array<?Array<number>>} */
this.playedRanges_ = [];

/** @private {?function()} */
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-lightbox/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const CONTENT_PROPS = {'part': 'scroller'};

/**
* @param {!LightboxDef.Props} props
* @param {{current: (!LightboxDef.LightboxApi|null)}} ref
* @param {{current: ?LightboxDef.LightboxApi}} ref
* @return {PreactDef.Renderable}
*/
function LightboxWithRef(
Expand Down
8 changes: 4 additions & 4 deletions extensions/amp-pan-zoom/0.1/amp-pan-zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ export class AmpPanZoom extends AMP.BaseElement {
/** @private */
this.disableDoubleTap_ = false;

/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenMouseDown_ = null;

/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenMouseUp_ = null;

/** @private {UnlistenDef|null} */
/** @private {?UnlistenDef} */
this.unlistenMouseMove_ = null;

/** @private */
Expand Down Expand Up @@ -478,7 +478,7 @@ export class AmpPanZoom extends AMP.BaseElement {

/**
* Unlisten a listener and clear. If null, does nothing
* @param {UnlistenDef|null} handle
* @param {?UnlistenDef} handle
* @private
*/
unlisten_(handle) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-pinterest/0.1/follow-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class FollowButton {
/**
* Determine the height of the contents to allow resizing after first layout.
*
* @return {!Promise<number|null>}
* @return {!Promise<?number>}
*/
height() {
return Promise.resolve(null);
Expand Down
Loading

0 comments on commit f8fdea2

Please sign in to comment.