Skip to content

Commit 089d5fe

Browse files
stepankuzminunderoot
authored andcommitted
Minor typing fixes (internal-1833)
* fix Map#_controlPositions * Expose `RequestTransformFunction`
1 parent 00dd47d commit 089d5fe

7 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/geo/projection/adjustments.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import {clamp, smoothstep} from '../../util/util';
66
import type Projection from './projection';
77
import type Transform from '../transform';
88

9-
export default function getProjectionAdjustments(transform: Transform, withoutRotation?: boolean): Array<number> {
9+
export default function getProjectionAdjustments(transform: Transform, withoutRotation?: boolean): number[] {
1010
const interpT = getProjectionInterpolationT(transform.projection, transform.zoom, transform.width, transform.height);
1111
const matrix = getShearAdjustment(transform.projection, transform.zoom, transform.center, interpT, withoutRotation);
1212

1313
const scaleAdjustment = getScaleAdjustment(transform);
1414
mat4.scale(matrix, matrix, [scaleAdjustment, scaleAdjustment, 1]);
1515

16-
// @ts-expect-error - TS2322 - Type 'mat4' is not assignable to type 'number[]'.
17-
return matrix;
16+
return matrix as number[];
1817
}
1918

2019
export function getScaleAdjustment(transform: Transform): number {
@@ -26,12 +25,12 @@ export function getScaleAdjustment(transform: Transform): number {
2625
return scaleAdjustment;
2726
}
2827

29-
export function getProjectionAdjustmentInverted(transform: Transform): Array<number> {
28+
export function getProjectionAdjustmentInverted(transform: Transform): number[] {
3029
const m = getProjectionAdjustments(transform, true);
31-
// @ts-expect-error - TS2322 - Type 'mat2' is not assignable to type 'number[]'.
32-
return mat2.invert([] as any, [
30+
return mat2.invert([] as unknown as mat2, [
3331
m[0], m[1],
34-
m[4], m[5]]);
32+
m[4], m[5]]
33+
) as number[];
3534
}
3635

3736
export function getProjectionInterpolationT(

src/geo/transform.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,8 +2309,7 @@ class Transform {
23092309
const mc = this.locationCoordinate(this.center);
23102310
const adjustments = mat4.identity([] as any);
23112311
mat4.translate(adjustments, adjustments, [mc.x * this.worldSize, mc.y * this.worldSize, 0]);
2312-
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'ReadonlyMat4'.
2313-
mat4.multiply(adjustments, adjustments, getProjectionAdjustments(this));
2312+
mat4.multiply(adjustments, adjustments, getProjectionAdjustments(this) as mat4);
23142313
mat4.translate(adjustments, adjustments, [-mc.x * this.worldSize, -mc.y * this.worldSize, 0]);
23152314
mat4.multiply(m, m, adjustments);
23162315
// @ts-expect-error - TS2345 - Argument of type 'number[] | Float32Array' is not assignable to parameter of type 'mat4'.

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export type {PluginStatus} from './source/rtl_text_plugin';
4242
export type {Event, ErrorEvent} from './util/evented';
4343
export type {GeoJSONFeature} from './util/vectortile_to_geojson';
4444
export type {PaddingOptions} from './geo/edge_insets';
45+
export type {RequestParameters} from './util/ajax';
46+
export type {RequestTransformFunction, ResourceType} from './util/mapbox';
4547
export type {LngLatLike, LngLatBoundsLike} from './geo/lng_lat';
4648

4749
export type {FeatureSelector} from './style/style';

src/ui/map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export class Map extends Camera {
420420
_canvasContainer: HTMLElement;
421421
_controlContainer: HTMLElement;
422422
_controlPositions: {
423-
[_: string]: HTMLElement;
423+
[p in ControlPosition]?: HTMLElement;
424424
};
425425
_interactive?: boolean;
426426
_showTileBoundaries?: boolean;

src/util/mapbox.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import {postData, getData} from './ajax';
2222
import {getLivePerformanceMetrics} from '../util/live_performance';
2323

2424
import type {LivePerformanceData} from '../util/live_performance';
25-
import type {RequestParameters, ResourceType} from './ajax';
25+
import type {RequestParameters, ResourceType as ResourceTypeEnum} from './ajax';
2626
import type {Cancelable} from '../types/cancelable';
2727
import type {TileJSON} from '../types/tilejson';
2828
import type {Map as MapboxMap} from "../ui/map";
2929

30-
type ResourceTypeEnum = keyof typeof ResourceType;
31-
export type RequestTransformFunction = (url: string, resourceType?: ResourceTypeEnum) => RequestParameters;
30+
export type ResourceType = keyof typeof ResourceTypeEnum;
31+
export type RequestTransformFunction = (url: string, resourceTypeEnum?: ResourceType) => RequestParameters;
3232

3333
type UrlObject = {
3434
protocol: string;
@@ -65,7 +65,7 @@ export class RequestManager {
6565
return Date.now() > this._skuTokenExpiresAt;
6666
}
6767

68-
transformRequest(url: string, type: ResourceTypeEnum): RequestParameters {
68+
transformRequest(url: string, type: ResourceType): RequestParameters {
6969
if (this._transformRequestFn) {
7070
return this._transformRequestFn(url, type) || {url};
7171
}

test/build/typings/compatibility-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ mercatorcoordinate.meterInMercatorCoordinateUnits() satisfies number;
949949

950950
expectType<mapboxgl.TransformRequestFunction>((url: string) => ({url}));
951951
// @ts-expect-error - incompatible
952-
expectType<mapboxgl.TransformRequestFunction>((url: string, resourceType: mapboxgl.ResourceType) => ({
952+
expectType<mapboxgl.TransformRequestFunction>((url: string, resourceTypeEnum: mapboxgl.ResourceTypeEnum) => ({
953953
url,
954954
credentials: "same-origin",
955955
headers: {"Accept-Encoding": "compress"},

test/build/typings/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const map = new mapboxgl.Map({
1717
attributionControl: false,
1818
});
1919

20+
const transformRequest: mapboxgl.RequestTransformFunction = (url: string, resourceTypeEnum: mapboxgl.ResourceType): mapboxgl.RequestParameters => {return {url}};
21+
2022
//
2123
// Events
2224
//

0 commit comments

Comments
 (0)