From 480b064f5d06f024bae767c63f3eb80e837fcbf8 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 12 Dec 2018 14:29:18 +0100 Subject: [PATCH 1/6] Remove type cast in ol/events --- src/ol/events.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/events.js b/src/ol/events.js index bb9a7d425e..200b048058 100644 --- a/src/ol/events.js +++ b/src/ol/events.js @@ -163,13 +163,13 @@ export function listen(target, type, listener, opt_this, opt_once) { listenerObj.callOnce = false; } } else { - listenerObj = /** @type {EventsKey} */ ({ + listenerObj = { bindTo: opt_this, callOnce: !!opt_once, listener: listener, target: target, type: type - }); + }; /** @type {import("./events/Target.js").default} */ (target). addEventListener(type, bindListener(listenerObj)); listeners.push(listenerObj); From 4010a644c0ae0b6b678c4474035cdb9f2d6476b2 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 12 Dec 2018 14:41:12 +0100 Subject: [PATCH 2/6] Remove type cast in ol/format/EsriJSON --- src/ol/format/EsriJSON.js | 85 ++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/src/ol/format/EsriJSON.js b/src/ol/format/EsriJSON.js index 9aaf63c1c9..03b25d30b4 100644 --- a/src/ol/format/EsriJSON.js +++ b/src/ol/format/EsriJSON.js @@ -211,7 +211,7 @@ class EsriJSON extends JSONFeature { * * @param {Array} features Features. * @param {import("./Feature.js").WriteOptions=} opt_options Write options. - * @return {Object} EsriJSON Object. + * @return {EsriJSONFeatureSet} EsriJSON Object. * @override * @api */ @@ -221,9 +221,9 @@ class EsriJSON extends JSONFeature { for (let i = 0, ii = features.length; i < ii; ++i) { objects.push(this.writeFeatureObject(features[i], opt_options)); } - return /** @type {EsriJSONFeatureSet} */ ({ + return { 'features': objects - }); + }; } } @@ -414,40 +414,41 @@ function readPolygonGeometry(object) { /** * @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("./Feature.js").WriteOptions=} opt_options Write options. - * @return {EsriJSONGeometry} EsriJSON geometry. + * @return {EsriJSONPoint} EsriJSON geometry. */ function writePointGeometry(geometry, opt_options) { const coordinates = /** @type {import("../geom/Point.js").default} */ (geometry).getCoordinates(); + /** @type {EsriJSONPoint} */ let esriJSON; const layout = /** @type {import("../geom/Point.js").default} */ (geometry).getLayout(); if (layout === GeometryLayout.XYZ) { - esriJSON = /** @type {EsriJSONPoint} */ ({ + esriJSON = { x: coordinates[0], y: coordinates[1], z: coordinates[2] - }); + }; } else if (layout === GeometryLayout.XYM) { - esriJSON = /** @type {EsriJSONPoint} */ ({ + esriJSON = { x: coordinates[0], y: coordinates[1], m: coordinates[2] - }); + }; } else if (layout === GeometryLayout.XYZM) { - esriJSON = /** @type {EsriJSONPoint} */ ({ + esriJSON = { x: coordinates[0], y: coordinates[1], z: coordinates[2], m: coordinates[3] - }); + }; } else if (layout === GeometryLayout.XY) { - esriJSON = /** @type {EsriJSONPoint} */ ({ + esriJSON = { x: coordinates[0], y: coordinates[1] - }); + }; } else { assert(false, 34); // Invalid geometry layout } - return /** @type {EsriJSONGeometry} */ (esriJSON); + return esriJSON; } @@ -474,15 +475,13 @@ function getHasZM(geometry) { function writeLineStringGeometry(geometry, opt_options) { const lineString = /** @type {import("../geom/LineString.js").default} */ (geometry); const hasZM = getHasZM(lineString); - return ( - /** @type {EsriJSONPolyline} */ { - hasZ: hasZM.hasZ, - hasM: hasZM.hasM, - paths: [ - /** @type {Array} */ (lineString.getCoordinates()) - ] - } - ); + return { + hasZ: hasZM.hasZ, + hasM: hasZM.hasM, + paths: [ + /** @type {Array} */ (lineString.getCoordinates()) + ] + }; } @@ -495,13 +494,11 @@ function writePolygonGeometry(geometry, opt_options) { const polygon = /** @type {import("../geom/Polygon.js").default} */ (geometry); // Esri geometries use the left-hand rule const hasZM = getHasZM(polygon); - return ( - /** @type {EsriJSONPolygon} */ { - hasZ: hasZM.hasZ, - hasM: hasZM.hasM, - rings: /** @type {Array>} */ (polygon.getCoordinates(false)) - } - ); + return { + hasZ: hasZM.hasZ, + hasM: hasZM.hasM, + rings: /** @type {Array>} */ (polygon.getCoordinates(false)) + }; } @@ -513,13 +510,11 @@ function writePolygonGeometry(geometry, opt_options) { function writeMultiLineStringGeometry(geometry, opt_options) { const multiLineString = /** @type {import("../geom/MultiLineString.js").default} */ (geometry); const hasZM = getHasZM(multiLineString); - return ( - /** @type {EsriJSONPolyline} */ { - hasZ: hasZM.hasZ, - hasM: hasZM.hasM, - paths: /** @type {Array>} */ (multiLineString.getCoordinates()) - } - ); + return { + hasZ: hasZM.hasZ, + hasM: hasZM.hasM, + paths: /** @type {Array>} */ (multiLineString.getCoordinates()) + }; } @@ -531,13 +526,11 @@ function writeMultiLineStringGeometry(geometry, opt_options) { function writeMultiPointGeometry(geometry, opt_options) { const multiPoint = /** @type {import("../geom/MultiPoint.js").default} */ (geometry); const hasZM = getHasZM(multiPoint); - return ( - /** @type {EsriJSONMultipoint} */ { - hasZ: hasZM.hasZ, - hasM: hasZM.hasM, - points: /** @type {Array} */ (multiPoint.getCoordinates()) - } - ); + return { + hasZ: hasZM.hasZ, + hasM: hasZM.hasM, + points: /** @type {Array} */ (multiPoint.getCoordinates()) + }; } @@ -555,11 +548,11 @@ function writeMultiPolygonGeometry(geometry, opt_options) { output.push(coordinates[i][x]); } } - return /** @type {EsriJSONPolygon} */ ({ + return { hasZ: hasZM.hasZ, hasM: hasZM.hasM, - rings: output - }); + rings: /** @type {Array>} */ (output) + }; } From 701e19c1c9c6c5496112f01f53f4908f09e65c73 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 12 Dec 2018 14:43:51 +0100 Subject: [PATCH 3/6] Remove type cast in ol/interaction/Snap --- src/ol/interaction/Snap.js | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index c40ee6b8de..a90475b016 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -451,13 +451,11 @@ class Snap extends PointerInteraction { vertexPixel = [Math.round(vertexPixel[0]), Math.round(vertexPixel[1])]; } } - return ( - /** @type {Result} */ ({ - snapped: snapped, - vertex: vertex, - vertexPixel: vertexPixel - }) - ); + return { + snapped: snapped, + vertex: vertex, + vertexPixel: vertexPixel + }; } /** @@ -479,10 +477,10 @@ class Snap extends PointerInteraction { const coordinates = polygon.getCoordinates()[0]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2); - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: segment - }); + }; this.rBush_.insert(boundingExtent(segment), segmentData); } } @@ -511,10 +509,10 @@ class Snap extends PointerInteraction { const coordinates = geometry.getCoordinates(); for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2); - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: segment - }); + }; this.rBush_.insert(boundingExtent(segment), segmentData); } } @@ -530,10 +528,10 @@ class Snap extends PointerInteraction { const coordinates = lines[j]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2); - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: segment - }); + }; this.rBush_.insert(boundingExtent(segment), segmentData); } } @@ -548,10 +546,10 @@ class Snap extends PointerInteraction { const points = geometry.getCoordinates(); for (let i = 0, ii = points.length; i < ii; ++i) { const coordinates = points[i]; - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: [coordinates, coordinates] - }); + }; this.rBush_.insert(geometry.getExtent(), segmentData); } } @@ -569,10 +567,10 @@ class Snap extends PointerInteraction { const coordinates = rings[j]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2); - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: segment - }); + }; this.rBush_.insert(boundingExtent(segment), segmentData); } } @@ -586,10 +584,10 @@ class Snap extends PointerInteraction { */ writePointGeometry_(feature, geometry) { const coordinates = geometry.getCoordinates(); - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: [coordinates, coordinates] - }); + }; this.rBush_.insert(geometry.getExtent(), segmentData); } @@ -604,10 +602,10 @@ class Snap extends PointerInteraction { const coordinates = rings[j]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2); - const segmentData = /** @type {SegmentData} */ ({ + const segmentData = { feature: feature, segment: segment - }); + }; this.rBush_.insert(boundingExtent(segment), segmentData); } } From d2cae9d3b7ca7271e528ec0de77a700865e6b088 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 12 Dec 2018 14:45:51 +0100 Subject: [PATCH 4/6] Remove type cast in ol/style/AtlasManager --- src/ol/style/AtlasManager.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ol/style/AtlasManager.js b/src/ol/style/AtlasManager.js index 495ffd8c7d..e98f493d4f 100644 --- a/src/ol/style/AtlasManager.js +++ b/src/ol/style/AtlasManager.js @@ -152,14 +152,12 @@ class AtlasManager { * entry, or `null` if the entry is not part of the atlases. */ mergeInfos_(info, hitInfo) { - return ( - /** @type {AtlasManagerInfo} */ ({ - offsetX: info.offsetX, - offsetY: info.offsetY, - image: info.image, - hitImage: hitInfo.image - }) - ); + return { + offsetX: info.offsetX, + offsetY: info.offsetY, + image: info.image, + hitImage: hitInfo.image + }; } /** From 056568c936bba137b28dc05b6fbda6f49405105f Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 12 Dec 2018 14:47:46 +0100 Subject: [PATCH 5/6] Remove type cast in ol/render/canvas/TextBuilder --- src/ol/render/canvas/TextBuilder.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ol/render/canvas/TextBuilder.js b/src/ol/render/canvas/TextBuilder.js index d6a06c23a6..e5850def1e 100644 --- a/src/ol/render/canvas/TextBuilder.js +++ b/src/ol/render/canvas/TextBuilder.js @@ -308,7 +308,7 @@ class CanvasTextBuilder extends CanvasBuilder { const strokeKey = this.strokeKey_; if (strokeState) { if (!(strokeKey in this.strokeStates)) { - this.strokeStates[strokeKey] = /** @type {import("../canvas.js").StrokeState} */ ({ + this.strokeStates[strokeKey] = { strokeStyle: strokeState.strokeStyle, lineCap: strokeState.lineCap, lineDashOffset: strokeState.lineDashOffset, @@ -316,24 +316,24 @@ class CanvasTextBuilder extends CanvasBuilder { lineJoin: strokeState.lineJoin, miterLimit: strokeState.miterLimit, lineDash: strokeState.lineDash - }); + }; } } const textKey = this.textKey_; if (!(textKey in this.textStates)) { - this.textStates[textKey] = /** @type {import("../canvas.js").TextState} */ ({ + this.textStates[textKey] = { font: textState.font, textAlign: textState.textAlign || defaultTextAlign, textBaseline: textState.textBaseline || defaultTextBaseline, scale: textState.scale - }); + }; } const fillKey = this.fillKey_; if (fillState) { if (!(fillKey in this.fillStates)) { - this.fillStates[fillKey] = /** @type {import("../canvas.js").FillState} */ ({ + this.fillStates[fillKey] = { fillStyle: fillState.fillStyle - }); + }; } } } From 29702e37509ffbda396aa242b8b7a358d9936cf7 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 12 Dec 2018 14:48:24 +0100 Subject: [PATCH 6/6] Remove type cast in ol/structs/LRUCache --- src/ol/structs/LRUCache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/structs/LRUCache.js b/src/ol/structs/LRUCache.js index b603969913..efed52b75f 100644 --- a/src/ol/structs/LRUCache.js +++ b/src/ol/structs/LRUCache.js @@ -261,12 +261,12 @@ class LRUCache extends EventTarget { set(key, value) { assert(!(key in this.entries_), 16); // Tried to set a value for a key that is used already - const entry = /** @type {Entry} */ ({ + const entry = { key_: key, newer: null, older: this.newest_, value_: value - }); + }; if (!this.newest_) { this.oldest_ = entry; } else {