Merge pull request #13301 from EvertEt/strictnullchecks-2

Improve some null types to prepare for strictNullChecks
This commit is contained in:
Tim Schaub
2022-02-09 04:51:54 -07:00
committed by GitHub
20 changed files with 41 additions and 39 deletions

View File

@@ -38,7 +38,7 @@ class ZoomToExtent extends Control {
}); });
/** /**
* @type {?import("../extent.js").Extent} * @type {?import("../extent.js").Extent|null}
* @protected * @protected
*/ */
this.extent = options.extent ? options.extent : null; this.extent = options.extent ? options.extent : null;

View File

@@ -83,7 +83,7 @@ export function replaceNode(newNode, oldNode) {
/** /**
* @param {Node} node The node to remove. * @param {Node} node The node to remove.
* @return {Node} The node that was removed or null. * @return {Node|null} The node that was removed or null.
*/ */
export function removeNode(node) { export function removeNode(node) {
return node && node.parentNode ? node.parentNode.removeChild(node) : null; return node && node.parentNode ? node.parentNode.removeChild(node) : null;

View File

@@ -80,7 +80,7 @@ class MVT extends FeatureFormat {
/** /**
* @private * @private
* @type {Array<string>} * @type {Array<string>|null}
*/ */
this.layers_ = options.layers ? options.layers : null; this.layers_ = options.layers ? options.layers : null;

View File

@@ -54,20 +54,20 @@ class WMSGetFeatureInfo extends XMLFeature {
/** /**
* @private * @private
* @type {Array<string>} * @type {Array<string>|null}
*/ */
this.layers_ = options.layers ? options.layers : null; this.layers_ = options.layers ? options.layers : null;
} }
/** /**
* @return {Array<string>} layers * @return {Array<string>|null} layers
*/ */
getLayers() { getLayers() {
return this.layers_; return this.layers_;
} }
/** /**
* @param {Array<string>} layers Layers to parse. * @param {Array<string>|null} layers Layers to parse.
*/ */
setLayers(layers) { setLayers(layers) {
this.layers_ = layers; this.layers_ = layers;

View File

@@ -168,7 +168,7 @@ class DragAndDrop extends Interaction {
/** /**
* @private * @private
* @type {HTMLElement} * @type {HTMLElement|null}
*/ */
this.target = options.target ? options.target : null; this.target = options.target ? options.target : null;
} }

View File

@@ -257,14 +257,14 @@ class Draw extends PointerInteraction {
/** /**
* Target source for drawn features. * Target source for drawn features.
* @type {VectorSource} * @type {VectorSource|null}
* @private * @private
*/ */
this.source_ = options.source ? options.source : null; this.source_ = options.source ? options.source : null;
/** /**
* Target collection for drawn features. * Target collection for drawn features.
* @type {import("../Collection.js").default<Feature>} * @type {import("../Collection.js").default<Feature>|null}
* @private * @private
*/ */
this.features_ = options.features ? options.features : null; this.features_ = options.features ? options.features : null;
@@ -1022,7 +1022,7 @@ class Draw extends PointerInteraction {
/** /**
* Stop drawing without adding the sketch feature to the target layer. * Stop drawing without adding the sketch feature to the target layer.
* @return {Feature<import("../geom/SimpleGeometry.js").default>} The sketch feature (or null if none). * @return {Feature<import("../geom/SimpleGeometry.js").default>|null} The sketch feature (or null if none).
* @private * @private
*/ */
abortDrawing_() { abortDrawing_() {

View File

@@ -115,7 +115,7 @@ class Snap extends PointerInteraction {
super(pointerOptions); super(pointerOptions);
/** /**
* @type {import("../source/Vector.js").default} * @type {import("../source/Vector.js").default|null}
* @private * @private
*/ */
this.source_ = options.source ? options.source : null; this.source_ = options.source ? options.source : null;
@@ -133,7 +133,7 @@ class Snap extends PointerInteraction {
this.edge_ = options.edge !== undefined ? options.edge : true; this.edge_ = options.edge !== undefined ? options.edge : true;
/** /**
* @type {import("../Collection.js").default<import("../Feature.js").default>} * @type {import("../Collection.js").default<import("../Feature.js").default>|null}
* @private * @private
*/ */
this.features_ = options.features ? options.features : null; this.features_ = options.features ? options.features : null;

View File

@@ -169,7 +169,7 @@ class Translate extends PointerInteraction {
this.startCoordinate_ = null; this.startCoordinate_ = null;
/** /**
* @type {Collection<import("../Feature.js").default>} * @type {Collection<import("../Feature.js").default>|null}
* @private * @private
*/ */
this.features_ = options.features !== undefined ? options.features : null; this.features_ = options.features !== undefined ? options.features : null;

View File

@@ -119,7 +119,7 @@ class BaseLayer extends BaseObject {
* @private * @private
*/ */
this.className_ = this.className_ =
properties.className !== undefined ? options.className : 'ol-layer'; properties.className !== undefined ? properties.className : 'ol-layer';
delete properties.className; delete properties.className;
this.setProperties(properties); this.setProperties(properties);
@@ -288,7 +288,7 @@ class BaseLayer extends BaseObject {
} }
/** /**
* Sets the backgrlound color. * Sets the background color.
* @param {BackgroundColor} [opt_background] Background color. * @param {BackgroundColor} [opt_background] Background color.
*/ */
setBackground(opt_background) { setBackground(opt_background) {

View File

@@ -127,7 +127,7 @@ class ImageSource extends Source {
/** /**
* @private * @private
* @type {Array<number>} * @type {Array<number>|null}
*/ */
this.resolutions_ = this.resolutions_ =
options.resolutions !== undefined ? options.resolutions : null; options.resolutions !== undefined ? options.resolutions : null;
@@ -146,7 +146,7 @@ class ImageSource extends Source {
} }
/** /**
* @return {Array<number>} Resolutions. * @return {Array<number>|null} Resolutions.
*/ */
getResolutions() { getResolutions() {
return this.resolutions_; return this.resolutions_;

View File

@@ -87,7 +87,7 @@ class Static extends ImageSource {
/** /**
* @private * @private
* @type {import("../size.js").Size} * @type {import("../size.js").Size|null}
*/ */
this.imageSize_ = options.imageSize ? options.imageSize : null; this.imageSize_ = options.imageSize ? options.imageSize : null;

View File

@@ -150,7 +150,7 @@ class Source extends BaseObject {
/** /**
* @abstract * @abstract
* @return {Array<number>|undefined} Resolutions. * @return {Array<number>|null} Resolutions.
*/ */
getResolutions() { getResolutions() {
return abstract(); return abstract();

View File

@@ -93,14 +93,13 @@ class TileSource extends Source {
options.tilePixelRatio !== undefined ? options.tilePixelRatio : 1; options.tilePixelRatio !== undefined ? options.tilePixelRatio : 1;
/** /**
* @type {import("../tilegrid/TileGrid.js").default} * @type {import("../tilegrid/TileGrid.js").default|null}
*/ */
this.tileGrid = options.tileGrid !== undefined ? options.tileGrid : null; this.tileGrid = options.tileGrid !== undefined ? options.tileGrid : null;
const tileSize = [256, 256]; const tileSize = [256, 256];
const tileGrid = options.tileGrid; if (this.tileGrid) {
if (tileGrid) { toSize(this.tileGrid.getTileSize(this.tileGrid.getMinZoom()), tileSize);
toSize(tileGrid.getTileSize(tileGrid.getMinZoom()), tileSize);
} }
/** /**
@@ -233,9 +232,12 @@ class TileSource extends Source {
} }
/** /**
* @return {Array<number>} Resolutions. * @return {Array<number>|null} Resolutions.
*/ */
getResolutions() { getResolutions() {
if (!this.tileGrid) {
return null;
}
return this.tileGrid.getResolutions(); return this.tileGrid.getResolutions();
} }
@@ -254,7 +256,7 @@ class TileSource extends Source {
/** /**
* Return the tile grid of the tile source. * Return the tile grid of the tile source.
* @return {import("../tilegrid/TileGrid.js").default} Tile grid. * @return {import("../tilegrid/TileGrid.js").default|null} Tile grid.
* @api * @api
*/ */
getTileGrid() { getTileGrid() {

View File

@@ -827,7 +827,7 @@ class VectorSource extends Source {
* `source.getFeatureById(2)` will return a feature with id `'2'` or `2`. * `source.getFeatureById(2)` will return a feature with id `'2'` or `2`.
* *
* @param {string|number} id Feature identifier. * @param {string|number} id Feature identifier.
* @return {import("../Feature.js").default<Geometry>} The feature (or `null` if not found). * @return {import("../Feature.js").default<Geometry>|null} The feature (or `null` if not found).
* @api * @api
*/ */
getFeatureById(id) { getFeatureById(id) {
@@ -839,7 +839,7 @@ class VectorSource extends Source {
* Get a feature by its internal unique identifier (using `getUid`). * Get a feature by its internal unique identifier (using `getUid`).
* *
* @param {string} uid Feature identifier. * @param {string} uid Feature identifier.
* @return {import("../Feature.js").default<Geometry>} The feature (or `null` if not found). * @return {import("../Feature.js").default<Geometry>|null} The feature (or `null` if not found).
*/ */
getFeatureByUid(uid) { getFeatureByUid(uid) {
const feature = this.uidIndex_[uid]; const feature = this.uidIndex_[uid];

View File

@@ -142,7 +142,7 @@ class VectorTile extends UrlTile {
/** /**
* @private * @private
* @type {import("../format/Feature.js").default} * @type {import("../format/Feature.js").default|null}
*/ */
this.format_ = options.format ? options.format : null; this.format_ = options.format ? options.format : null;

View File

@@ -4,7 +4,7 @@
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("../color.js").Color|import("../colorlike.js").ColorLike} [color=null] A color, gradient or pattern. * @property {import("../color.js").Color|import("../colorlike.js").ColorLike|null} [color=null] A color, gradient or pattern.
* See {@link module:ol/color~Color} and {@link module:ol/colorlike~ColorLike} for possible formats. * See {@link module:ol/color~Color} and {@link module:ol/colorlike~ColorLike} for possible formats.
* Default null; if null, the Canvas/renderer default black will be used. * Default null; if null, the Canvas/renderer default black will be used.
*/ */
@@ -23,7 +23,7 @@ class Fill {
/** /**
* @private * @private
* @type {import("../color.js").Color|import("../colorlike.js").ColorLike} * @type {import("../color.js").Color|import("../colorlike.js").ColorLike|null}
*/ */
this.color_ = options.color !== undefined ? options.color : null; this.color_ = options.color !== undefined ? options.color : null;
} }
@@ -42,7 +42,7 @@ class Fill {
/** /**
* Get the fill color. * Get the fill color.
* @return {import("../color.js").Color|import("../colorlike.js").ColorLike} Color. * @return {import("../color.js").Color|import("../colorlike.js").ColorLike|null} Color.
* @api * @api
*/ */
getColor() { getColor() {
@@ -52,7 +52,7 @@ class Fill {
/** /**
* Set the color. * Set the color.
* *
* @param {import("../color.js").Color|import("../colorlike.js").ColorLike} color Color. * @param {import("../color.js").Color|import("../colorlike.js").ColorLike|null} color Color.
* @api * @api
*/ */
setColor(color) { setColor(color) {

View File

@@ -455,7 +455,7 @@ export function toFunction(obj) {
} }
/** /**
* @type {Array<Style>} * @type {Array<Style>|null}
*/ */
let defaultStyles = null; let defaultStyles = null;

View File

@@ -168,7 +168,7 @@ class Text {
/** /**
* @private * @private
* @type {Array<number>} * @type {Array<number>|null}
*/ */
this.padding_ = options.padding === undefined ? null : options.padding; this.padding_ = options.padding === undefined ? null : options.padding;
} }
@@ -201,7 +201,7 @@ class Text {
backgroundStroke: this.getBackgroundStroke() backgroundStroke: this.getBackgroundStroke()
? this.getBackgroundStroke().clone() ? this.getBackgroundStroke().clone()
: undefined, : undefined,
padding: this.getPadding(), padding: this.getPadding() || undefined,
}); });
} }
@@ -359,7 +359,7 @@ class Text {
/** /**
* Get the padding for the text. * Get the padding for the text.
* @return {Array<number>} Padding. * @return {Array<number>|null} Padding.
* @api * @api
*/ */
getPadding() { getPadding() {
@@ -530,7 +530,7 @@ class Text {
/** /**
* Set the padding (`[top, right, bottom, left]`). * Set the padding (`[top, right, bottom, left]`).
* *
* @param {!Array<number>} padding Padding. * @param {Array<number>|null} padding Padding.
* @api * @api
*/ */
setPadding(padding) { setPadding(padding) {

View File

@@ -117,7 +117,7 @@ class TileGrid {
/** /**
* @private * @private
* @type {import("../coordinate.js").Coordinate} * @type {import("../coordinate.js").Coordinate|null}
*/ */
this.origin_ = options.origin !== undefined ? options.origin : null; this.origin_ = options.origin !== undefined ? options.origin : null;

View File

@@ -29,7 +29,7 @@ worker.onmessage = (event) => {
const indexBuffer = new Uint32Array(indicesCount); const indexBuffer = new Uint32Array(indicesCount);
const vertexBuffer = new Float32Array(verticesCount); const vertexBuffer = new Float32Array(verticesCount);
let bufferPositions = null; let bufferPositions;
for (let i = 0; i < renderInstructions.length; i += instructionsCount) { for (let i = 0; i < renderInstructions.length; i += instructionsCount) {
bufferPositions = writePointFeatureToBuffers( bufferPositions = writePointFeatureToBuffers(
renderInstructions, renderInstructions,