Skip to content

Commit 30ae3e9

Browse files
authored
Merge pull request TerriaJS#7050 from TerriaJS/react-18-part-2
React 18 upgrade prework
2 parents ec1bc87 + 95547c8 commit 30ae3e9

File tree

96 files changed

+558
-851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+558
-851
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"files": ["**/*.ts", "**/*.tsx"],
114114
"rules": {
115115
// @TODO: revise these rules
116+
"@typescript-eslint/consistent-type-assertions": "error",
116117
"@typescript-eslint/no-unused-vars": [
117118
"warn",
118119
{

lib/Charts/ChartView.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ export default class ChartView {
1616

1717
@computed
1818
get chartableItems(): ChartableMixin.Instance[] {
19-
return <any>(
20-
this.terria.workbench.items.filter(
21-
(item) => ChartableMixin.isMixedInto(item) && item.chartItems.length > 0
22-
)
23-
);
19+
return this.terria.workbench.items.filter(
20+
(item) => ChartableMixin.isMixedInto(item) && item.chartItems.length > 0
21+
) as any;
2422
}
2523

2624
/**

lib/Core/instanceOf.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export default function instanceOf<T>(
1515
type: Class<T>,
1616
instance: any
1717
): instance is T {
18-
return instance instanceof <any>type;
18+
return instance instanceof (type as any);
1919
}

lib/Core/markdownToHtml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function markdownToHtml(
5454
// (typeof string === 'string'). So if this isn't a string primitive, call toString
5555
// on it in order to make it one.
5656
if (markdownString && typeof markdownString !== "string") {
57-
stringToParse = (<any>markdownString).toString();
57+
stringToParse = (markdownString as any).toString();
5858
}
5959
if (markdownOptions.injectTermsAsTooltips && markdownOptions.tooltipTerms) {
6060
stringToParse = injectTerms(stringToParse, markdownOptions.tooltipTerms);

lib/Map/Cesium/CesiumRenderLoopPauser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ export default class CesiumRenderLoopPauser {
308308

309309
const cameraMovedInLastSecond = now - this._lastCameraMoveTime < 1000;
310310

311-
const surface = (<any>scene.globe)._surface;
311+
const surface = (scene.globe as any)._surface;
312312
const terrainTilesWaiting =
313313
!surface._tileProvider ||
314314
surface._tileLoadQueueHigh.length > 0 ||
315315
surface._tileLoadQueueMedium.length > 0 ||
316316
surface._tileLoadQueueLow.length > 0 ||
317317
surface._debug.tilesWaitingForChildren > 0;
318-
const tweens = (<any>scene).tweens;
318+
const tweens = (scene as any).tweens;
319319

320320
if (
321321
!cameraMovedInLastSecond &&

lib/Map/ImageryProvider/MapboxVectorTileImageryProvider.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -184,35 +184,35 @@ export default class MapboxVectorTileImageryProvider
184184
get credit(): Credit {
185185
let credit = this._credit;
186186
if (credit === undefined) {
187-
return <any>undefined;
187+
return undefined as any;
188188
} else if (typeof credit === "string") {
189189
credit = new Credit(credit);
190190
}
191191
return credit;
192192
}
193193

194194
get defaultAlpha(): number {
195-
return <any>undefined;
195+
return undefined as any;
196196
}
197197

198198
get defaultBrightness(): number {
199-
return <any>undefined;
199+
return undefined as any;
200200
}
201201

202202
get defaultContrast(): number {
203-
return <any>undefined;
203+
return undefined as any;
204204
}
205205

206206
get defaultGamma(): number {
207-
return <any>undefined;
207+
return undefined as any;
208208
}
209209

210210
get defaultHue(): number {
211-
return <any>undefined;
211+
return undefined as any;
212212
}
213213

214214
get defaultSaturation(): number {
215-
return <any>undefined;
215+
return undefined as any;
216216
}
217217

218218
get defaultMagnificationFilter(): any {
@@ -224,15 +224,15 @@ export default class MapboxVectorTileImageryProvider
224224
}
225225

226226
get proxy(): DefaultProxy {
227-
return <any>undefined;
227+
return undefined as any;
228228
}
229229

230230
get readyPromise(): Promise<boolean> {
231231
return Promise.resolve(true);
232232
}
233233

234234
get tileDiscardPolicy(): TileDiscardPolicy {
235-
return <any>undefined;
235+
return undefined as any;
236236
}
237237

238238
getTileCredits(_x: number, _y: number, _level: number): Credit[] {
@@ -325,7 +325,7 @@ export default class MapboxVectorTileImageryProvider
325325

326326
let pos;
327327

328-
let extentFactor = canvas.width / (<any>layer).extent; // Vector tile works with extent [0, 4095], but canvas is only [0,255]
328+
let extentFactor = canvas.width / (layer as any).extent; // Vector tile works with extent [0, 4095], but canvas is only [0,255]
329329

330330
// Features
331331
for (let i = 0; i < layer.length; i++) {

lib/Map/ImageryProvider/ProtomapsImageryProvider.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,17 @@ export default class ProtomapsImageryProvider
282282
readonly defaultNightAlpha = undefined;
283283
readonly defaultDayAlpha = undefined;
284284
readonly hasAlphaChannel = true;
285-
readonly defaultAlpha = <any>undefined;
286-
readonly defaultBrightness = <any>undefined;
287-
readonly defaultContrast = <any>undefined;
288-
readonly defaultGamma = <any>undefined;
289-
readonly defaultHue = <any>undefined;
290-
readonly defaultSaturation = <any>undefined;
285+
readonly defaultAlpha = undefined as any;
286+
readonly defaultBrightness = undefined as any;
287+
readonly defaultContrast = undefined as any;
288+
readonly defaultGamma = undefined as any;
289+
readonly defaultHue = undefined as any;
290+
readonly defaultSaturation = undefined as any;
291291
readonly defaultMagnificationFilter = undefined as any;
292292
readonly defaultMinificationFilter = undefined as any;
293-
readonly proxy = <any>undefined;
293+
readonly proxy = undefined as any;
294294
readonly readyPromise = Promise.resolve(true);
295-
readonly tileDiscardPolicy = <any>undefined;
295+
readonly tileDiscardPolicy = undefined as any;
296296

297297
// Protomaps properties
298298
/** Data object from constructor options (this is transformed into `source`) */

lib/Map/Leaflet/ImageryProviderLeafletGridLayer.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ export default class ImageryProviderLeafletGridLayer extends L.GridLayer {
115115
}
116116

117117
createTile(tilePoint: L.Coords, done: L.DoneCallback) {
118-
const canvas = <HTMLCanvasElement>(
119-
L.DomUtil.create("canvas", "leaflet-tile")
120-
);
118+
const canvas = L.DomUtil.create(
119+
"canvas",
120+
"leaflet-tile"
121+
) as HTMLCanvasElement;
121122
const size = this.getTileSize();
122123
canvas.width = size.x;
123124
canvas.height = size.y;

lib/Map/Leaflet/ImageryProviderLeafletTileLayer.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
5555
readonly imageryProvider: ImageryProvider,
5656
options: L.TileLayerOptions = {}
5757
) {
58-
super(<any>undefined, {
58+
super(undefined as any, {
5959
...options,
6060
updateInterval: defined((imageryProvider as any)._leafletUpdateInterval)
6161
? (imageryProvider as any)._leafletUpdateInterval
@@ -147,7 +147,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
147147

148148
createTile(coords: L.Coords, done: L.DoneCallback) {
149149
// Create a tile (Image) as normal.
150-
const tile = <HTMLImageElement>super.createTile(coords, done);
150+
const tile = super.createTile(coords, done) as HTMLImageElement;
151151

152152
// By default, Leaflet handles tile load errors by setting the Image to the error URL and raising
153153
// an error event. We want to first raise an error event that optionally returns a promise and
@@ -162,7 +162,12 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
162162
.catch((e: unknown) => {
163163
// The tile has failed irrecoverably, so invoke Leaflet's standard
164164
// tile error handler.
165-
(<any>L.TileLayer).prototype._tileOnError.call(this, done, tile, e);
165+
(L.TileLayer as any).prototype._tileOnError.call(
166+
this,
167+
done,
168+
tile,
169+
e
170+
);
166171
});
167172
return;
168173
}
@@ -176,7 +181,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
176181
};
177182

178183
L.DomEvent.on(tile, "error", (e) => {
179-
const level = (<any>this)._getLevelFromZ(coords);
184+
const level = (this as any)._getLevelFromZ(coords);
180185
const message = i18next.t("map.cesium.failedToObtain", {
181186
x: coords.x,
182187
y: coords.y,
@@ -190,7 +195,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
190195
coords.x,
191196
coords.y,
192197
level,
193-
<any>e
198+
e as any
194199
// TODO: bring terriajs-cesium retry logic to cesium
195200
//doRequest
196201
);
@@ -230,7 +235,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
230235
this._delayedUpdate = undefined;
231236
}
232237

233-
this._delayedUpdate = <any>setTimeout(() => {
238+
this._delayedUpdate = setTimeout(() => {
234239
this._delayedUpdate = undefined;
235240

236241
// If we're no longer attached to a map, do nothing.
@@ -272,19 +277,19 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
272277
}
273278

274279
if (isDefined(this.imageryProvider.credit)) {
275-
(<any>this._map).attributionControl.addAttribution(
280+
(this._map as any).attributionControl.addAttribution(
276281
getCreditHtml(this.imageryProvider.credit)
277282
);
278283
}
279284

280285
this._usable = true;
281286

282287
this._update();
283-
}, this._leafletUpdateInterval);
288+
}, this._leafletUpdateInterval) as any;
284289
}
285290

286291
if (this._usable) {
287-
(<any>L.TileLayer).prototype._update.apply(this, args);
292+
(L.TileLayer as any).prototype._update.apply(this, args);
288293

289294
this._updateAttribution();
290295
}
@@ -348,9 +353,11 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
348353

349354
for (let j = ne.y; j < sw.y; ++j) {
350355
for (let i = sw.x; i < ne.x; ++i) {
351-
const credits = <Credit[]>(
352-
this.imageryProvider.getTileCredits(i, j, zoom)
353-
);
356+
const credits = this.imageryProvider.getTileCredits(
357+
i,
358+
j,
359+
zoom
360+
) as Credit[];
354361
if (!defined(credits)) {
355362
continue;
356363
}
@@ -365,7 +372,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
365372
nextCredits.push(credit);
366373

367374
if (!credit._shownInLeafletLastUpdate) {
368-
(<any>this._map).attributionControl.addAttribution(
375+
(this._map as any).attributionControl.addAttribution(
369376
getCreditHtml(credit)
370377
);
371378
}
@@ -376,7 +383,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
376383
// Remove attributions that applied last update but not this one.
377384
for (let i = 0; i < this._previousCredits.length; ++i) {
378385
if (!this._previousCredits[i]._shownInLeaflet) {
379-
(<any>this._map).attributionControl.removeAttribution(
386+
(this._map as any).attributionControl.removeAttribution(
380387
getCreditHtml(this._previousCredits[i])
381388
);
382389
this._previousCredits[i]._shownInLeafletLastUpdate = false;
@@ -426,7 +433,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
426433
TerriaError.from(
427434
e,
428435
`An error ocurred while calling \`ImageryProvider#.pickFeatures\`. \`ImageryProvider.url = ${
429-
(<any>this.imageryProvider).url
436+
(this.imageryProvider as any).url
430437
}\``
431438
).log();
432439
}
@@ -441,13 +448,13 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
441448
for (let i = 0; i < this._previousCredits.length; ++i) {
442449
this._previousCredits[i]._shownInLeafletLastUpdate = false;
443450
this._previousCredits[i]._shownInLeaflet = false;
444-
(<any>map).attributionControl.removeAttribution(
451+
(map as any).attributionControl.removeAttribution(
445452
getCreditHtml(this._previousCredits[i])
446453
);
447454
}
448455

449456
if (this._usable && defined(this.imageryProvider.credit)) {
450-
(<any>map).attributionControl.removeAttribution(
457+
(map as any).attributionControl.removeAttribution(
451458
getCreditHtml(this.imageryProvider.credit)
452459
);
453460
}

lib/Map/Leaflet/LeafletDataSourceDisplay.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class LeafletDataSourceDisplay {
133133
const dataSources = this._dataSourceCollection;
134134
const length = dataSources.length;
135135
for (let i = 0; i < length; i++) {
136-
const dataSource = <LeafletDataSource>dataSources.get(i);
136+
const dataSource = dataSources.get(i) as LeafletDataSource;
137137
if (isDefined(dataSource.update)) {
138138
result = dataSource.update(time) && result;
139139
}

lib/Map/Leaflet/LeafletSelectionIndicator.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export default class LeafletSelectionIndicator {
4949
});
5050

5151
this._marker.addTo(this._leaflet.map);
52-
this._selectionIndicatorDomElement = (<any>this._marker)._icon.children[0];
52+
this._selectionIndicatorDomElement = (
53+
this._marker as any
54+
)._icon.children[0];
5355
}
5456

5557
setLatLng(latlng: L.LatLng) {

lib/Map/Leaflet/LeafletVisualizer.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class LeafletGeomVisualizer {
463463
for (const prop in iconOptions) {
464464
if (
465465
isDefined(marker.options.icon) &&
466-
iconOptions[prop] !== (<any>marker.options.icon.options)[prop]
466+
iconOptions[prop] !== (marker.options.icon.options as any)[prop]
467467
) {
468468
redrawIcon = true;
469469
break;
@@ -592,7 +592,7 @@ class LeafletGeomVisualizer {
592592
for (const prop in iconOptions) {
593593
if (
594594
isDefined(marker.options.icon) &&
595-
iconOptions[prop] !== (<any>marker.options.icon.options)[prop]
595+
iconOptions[prop] !== (marker.options.icon.options as any)[prop]
596596
) {
597597
redrawLabel = true;
598598
break;
@@ -1025,7 +1025,9 @@ class LeafletGeomVisualizer {
10251025
}
10261026

10271027
for (const prop in polylineOptions) {
1028-
if ((<any>polylineOptions)[prop] !== (<any>polyline.options)[prop]) {
1028+
if (
1029+
(polylineOptions as any)[prop] !== (polyline.options as any)[prop]
1030+
) {
10291031
polyline.setStyle(polylineOptions);
10301032
break;
10311033
}

lib/ModelMixins/Cesium3dTilesMixin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function Cesium3dTilesMixin<T extends AbstractConstructor<BaseType>>(Base: T) {
333333
const options: any = {};
334334
if (isDefined(this.options)) {
335335
Object.keys(OptionsTraits.traits).forEach((name) => {
336-
options[name] = (<any>this.options)[name];
336+
options[name] = (this.options as any)[name];
337337
});
338338
}
339339
return options;

0 commit comments

Comments
 (0)