Skip to content

Commit 51b194a

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Improve internal TypeScript typings (internal-8366)
GitOrigin-RevId: 05c094abca93dcebebf0fd32cf5be307c4abea08
1 parent 9b7d806 commit 51b194a

25 files changed

+59
-127
lines changed

3d-style/source/tiled_3d_model_source.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,14 @@ class Tiled3DModelSource extends Evented<SourceEvents> implements ISource {
179179
tile.request = tile.actor.send('reloadTile', params, done.bind(this));
180180
}
181181

182-
function done(err?: AJAXError | null, data?: WorkerSourceVectorTileResult | null) {
182+
function done(this: Tiled3DModelSource, err?: AJAXError | null, data?: WorkerSourceVectorTileResult | null) {
183183
if (tile.aborted) return callback(null);
184184

185185
if (err && err.status !== 404) {
186186
return callback(err);
187187
}
188188

189-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
190189
if (this.map._refreshExpiredTiles && data) tile.setExpiryData(data);
191-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
192190
tile.loadModelData(data, this.map.painter);
193191

194192
tile.state = 'loaded';

src/source/canvas_source.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,13 @@ class CanvasSource extends ImageSource<'canvas'> {
127127
}
128128

129129
this.play = function () {
130-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131130
this._playing = true;
132-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
133131
this.map.triggerRepaint();
134132
};
135133

136134
this.pause = function () {
137-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
138135
if (this._playing) {
139-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
140136
this.prepare();
141-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
142137
this._playing = false;
143138
}
144139
};

src/source/custom_source.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,12 @@ class CustomSource<T> extends Evented<SourceEvents> implements ISource {
213213
}
214214

215215
// @ts-expect-error - TS2339 - Property 'update' does not exist on type 'CustomSourceInterface<T>'.
216-
217216
implementation.update = this._update.bind(this);
218217

219218
// @ts-expect-error - TS2339 - Property 'clearTiles' does not exist on type 'CustomSourceInterface<T>'.
220-
221219
implementation.clearTiles = this._clearTiles.bind(this);
222220

223221
// @ts-expect-error - TS2339 - Property 'coveringTiles' does not exist on type 'CustomSourceInterface<T>'.
224-
225222
implementation.coveringTiles = this._coveringTiles.bind(this);
226223

227224
Object.assign(this, pick(implementation, ['dataType', 'scheme', 'minzoom', 'maxzoom', 'tileSize', 'attribution', 'minTileCacheSize', 'maxTileCacheSize']));
@@ -283,7 +280,7 @@ class CustomSource<T> extends Evented<SourceEvents> implements ISource {
283280

284281
tile.request.cancel = () => controller.abort();
285282

286-
function tileLoaded(data?: T | null) {
283+
function tileLoaded(this: CustomSource<T>, data?: T | null) {
287284
delete tile.request;
288285

289286
if (tile.aborted) {
@@ -303,21 +300,17 @@ class CustomSource<T> extends Evented<SourceEvents> implements ISource {
303300
// mark the tile as `loaded` and use an an empty image as tile data.
304301
// A map will render nothing in the tile’s space.
305302
if (data === null) {
306-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
307303
const emptyImage = {width: this.tileSize, height: this.tileSize, data: null};
308-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
309-
this.loadTileData(tile, emptyImage);
304+
this.loadTileData(tile, emptyImage as T);
310305
tile.state = 'loaded';
311306
return callback(null);
312307
}
313308

314309
if (!isRaster(data)) {
315310
tile.state = 'errored';
316-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
317311
return callback(new Error(`Can't infer data type for ${this.id}, only raster data supported at the moment`));
318312
}
319313

320-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
321314
this.loadTileData(tile, data);
322315
tile.state = 'loaded';
323316
callback(null);

src/source/geojson_worker_source.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,15 @@ export interface GeoJSONIndex {
6060
getLeaves?: (clusterId: number, limit: number, offset: number) => Array<GeoJSON.Feature>;
6161
}
6262

63-
function loadGeoJSONTile(params: WorkerSourceVectorTileRequest, callback: LoadVectorDataCallback): undefined {
63+
function loadGeoJSONTile(this: GeoJSONWorkerSource, params: WorkerSourceVectorTileRequest, callback: LoadVectorDataCallback): undefined {
6464
const canonical = params.tileID.canonical;
6565

66-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6766
if (!this._geoJSONIndex) {
6867
callback(null, null); // we couldn't load the file
6968
return;
7069
}
7170

72-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
71+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7372
const geoJSONTile = this._geoJSONIndex.getTile(canonical.z, canonical.x, canonical.y);
7473
if (!geoJSONTile) {
7574
callback(null, null); // nothing in the given tile
@@ -200,8 +199,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
200199
geojsonvt(data, params.geojsonVtOptions);
201200

202201
} catch (err) {
203-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
204-
return callback(err);
202+
return callback(err as Error);
205203
}
206204

207205
const result: {resourceTiming?: ResourceTiming} = {};
@@ -282,8 +280,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
282280
try {
283281
callback(null, this._geoJSONIndex.getClusterExpansionZoom(params.clusterId));
284282
} catch (e) {
285-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
286-
callback(e);
283+
callback(e as Error);
287284
}
288285
}
289286

@@ -293,8 +290,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
293290
try {
294291
callback(null, this._geoJSONIndex.getChildren(params.clusterId));
295292
} catch (e) {
296-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
297-
callback(e);
293+
callback(e as Error);
298294
}
299295
}
300296

@@ -306,8 +302,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
306302
try {
307303
callback(null, this._geoJSONIndex.getLeaves(params.clusterId, params.limit, params.offset));
308304
} catch (e) {
309-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
310-
callback(e);
305+
callback(e as Error);
311306
}
312307
}
313308
}

src/source/raster_array_tile.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ class RasterArrayTile extends Tile implements Tile {
177177

178178
callback(null, (this.entireBuffer || dataBuffer), headers);
179179
} catch (error) {
180-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
181-
callback(error);
180+
callback(error as Error);
182181
}
183182
});
184183

src/source/raster_array_tile_worker_source.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,16 @@ class RasterArrayWorkerTile {
6060
const bufferSlice = buffer.slice(range.firstByte, range.lastByte + 1);
6161
const decodingTask = MapboxRasterTile.performDecoding(bufferSlice, task)
6262
.then(result => task.complete(null, result))
63-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
64-
.catch(error => task.complete(error, null));
63+
.catch((error: Error) => task.complete(error, null));
6564

6665
decodingTasks.push(decodingTask);
6766
}
6867

6968
Promise.allSettled(decodingTasks)
7069
.then(() => callback(null, mrt))
71-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
72-
.catch(error => callback(error));
70+
.catch((error: Error) => callback(error));
7371
} catch (error) {
74-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
75-
callback(error);
72+
callback(error as Error);
7673
}
7774
}
7875
}
@@ -140,8 +137,7 @@ class RasterArrayTileWorkerSource implements WorkerSource {
140137
decodeRasterArray(params: ActorMessages['decodeRasterArray']['params'], callback: ActorMessages['decodeRasterArray']['callback']) {
141138
MapboxRasterTile.performDecoding(params.buffer, params.task)
142139
.then(result => callback(null, result))
143-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
144-
.catch(error => callback(error));
140+
.catch((error: Error) => callback(error));
145141
}
146142
}
147143

src/source/raster_dem_tile_source.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RasterDEMTileSource extends RasterTileSource<'raster-dem'> {
3434
tile.request = getImage(this.map._requestManager.transformRequest(url, ResourceType.Tile), imageLoaded.bind(this));
3535

3636
function imageLoaded(
37+
this: RasterDEMTileSource,
3738
err?: Error | null,
3839
img?: TextureImage | null,
3940
responseHeaders?: Headers,
@@ -47,7 +48,6 @@ class RasterDEMTileSource extends RasterTileSource<'raster-dem'> {
4748
callback(err);
4849
} else if (img) {
4950
const expiryData = getExpiryDataFromHeaders(responseHeaders);
50-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5151
if (this.map._refreshExpiredTiles) tile.setExpiryData(expiryData);
5252
const transfer = ImageBitmap && img instanceof ImageBitmap && offscreenCanvasSupported();
5353
// DEMData uses 1px padding. Handle cases with image buffer of 1 and 2 pxs, the rest assume default buffer 0
@@ -57,7 +57,6 @@ class RasterDEMTileSource extends RasterTileSource<'raster-dem'> {
5757
const padding = 1 - buffer;
5858
const borderReady = padding < 1;
5959
if (!borderReady && !tile.neighboringTiles) {
60-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
6160
tile.neighboringTiles = this._getNeighboringTiles(tile.tileID);
6261
}
6362

@@ -66,28 +65,23 @@ class RasterDEMTileSource extends RasterTileSource<'raster-dem'> {
6665
const params: WorkerSourceDEMTileRequest = {
6766
uid: tile.uid,
6867
tileID: tile.tileID,
69-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
7068
source: this.id,
71-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
7269
type: this.type,
73-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
7470
scope: this.scope,
7571
rawImageData,
76-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
7772
encoding: this.encoding,
7873
padding
7974
};
8075

8176
if (!tile.actor || tile.state === 'expired') {
82-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
8377
tile.actor = this.dispatcher.getActor();
8478

8579
tile.actor.send('loadTile', params, done.bind(this), undefined, true);
8680
}
8781
}
8882
}
8983

90-
function done(err?: Error | null, dem?: DEMData | null) {
84+
function done(this: RasterDEMTileSource, err?: Error | null, dem?: DEMData | null) {
9185
if (err) {
9286
tile.state = 'errored';
9387
callback(err);

src/source/worker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ export default class MapWorker {
288288
this.self.importScripts(params.url);
289289
callback();
290290
} catch (e) {
291-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
292-
callback(e.toString());
291+
callback(e as Error);
293292
}
294293
}
295294

@@ -324,8 +323,7 @@ export default class MapWorker {
324323
}
325324
}
326325
} catch (e) {
327-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
328-
callback(e.toString());
326+
callback(e as Error);
329327
}
330328
}
331329

src/style-spec/expression/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,11 @@ export class StyleExpression {
150150
}
151151
return val;
152152
} catch (e) {
153-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
154-
if (!this._warningHistory[e.message]) {
155-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
156-
this._warningHistory[e.message] = true;
153+
const error = e as Error;
154+
if (!this._warningHistory[error.message]) {
155+
this._warningHistory[error.message] = true;
157156
if (typeof console !== 'undefined') {
158-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
159-
console.warn(`Failed to evaluate expression "${JSON.stringify(this.expression.serialize())}". ${e.message}`);
157+
console.warn(`Failed to evaluate expression "${JSON.stringify(this.expression.serialize())}". ${error.message}`);
160158
}
161159
}
162160
return this._defaultValue;

src/style-spec/read_style.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export default function readStyle(style: string | Buffer | StyleSpecification):
88
try {
99
return (jsonlint as {parse: (input: string) => StyleSpecification}).parse(style.toString());
1010
} catch (e) {
11-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
12-
throw new ParsingError(e);
11+
throw new ParsingError(e as Error);
1312
}
1413
}
1514

0 commit comments

Comments
 (0)