Skip to content

Commit 4f856f0

Browse files
committed
[v8] Align type names across modules (#2468)
1 parent 2785a32 commit 4f856f0

33 files changed

+661
-1241
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
check_branch:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111
outputs:
1212
should_build: ${{ steps.permitted.outputs.result }}
1313

@@ -30,7 +30,7 @@ jobs:
3030
echo "result=${result}" >> "$GITHUB_OUTPUT"
3131
3232
release:
33-
runs-on: ubuntu-latest
33+
runs-on: ubuntu-22.04
3434
needs: check_branch
3535
permissions:
3636
contents: write
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
import * as React from 'react';
22
import {useEffect, memo} from 'react';
33
import {applyReactStyle} from '../utils/apply-react-style';
4-
import useControl from './use-control';
4+
import {useControl} from './use-control';
55

6-
import type {ControlPosition, AttributionControlInstance} from '../types';
6+
import type {ControlPosition, AttributionControlOptions} from '../types/lib';
77

8-
export type AttributionControlProps<OptionsT> = OptionsT & {
8+
export type AttributionControlProps = AttributionControlOptions & {
99
/** Placement of the control relative to the map. */
1010
position?: ControlPosition;
1111
/** CSS style override, applied to the control's container */
1212
style?: React.CSSProperties;
1313
};
1414

15-
function AttributionControl<AttributionControlOptions, ControlT extends AttributionControlInstance>(
16-
props: AttributionControlProps<AttributionControlOptions>
17-
): null {
18-
const ctrl = useControl<ControlT>(
19-
({mapLib}) => new mapLib.AttributionControl(props) as ControlT,
20-
{
21-
position: props.position
22-
}
23-
);
15+
function _AttributionControl(props: AttributionControlProps) {
16+
const ctrl = useControl(({mapLib}) => new mapLib.AttributionControl(props), {
17+
position: props.position
18+
});
2419

2520
useEffect(() => {
21+
// @ts-expect-error accessing private member
2622
applyReactStyle(ctrl._container, props.style);
2723
}, [props.style]);
2824

2925
return null;
3026
}
3127

32-
export default memo(AttributionControl);
28+
export const AttributionControl = memo(_AttributionControl);

modules/main/src/mapbox-legacy/components/fullscreen-control.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import * as React from 'react';
33
import {useEffect, memo} from 'react';
44
import {applyReactStyle} from '../utils/apply-react-style';
5-
import useControl from './use-control';
5+
import {useControl} from './use-control';
66

7-
import type {ControlPosition, FullscreenControlInstance} from '../types';
7+
import type {ControlPosition, FullscreenControlOptions} from '../types/lib';
88

9-
export type FullscreenControlProps<OptionsT> = Omit<OptionsT, 'container'> & {
9+
export type FullscreenControlProps = Omit<FullscreenControlOptions, 'container'> & {
1010
/** Id of the DOM element which should be made full screen. By default, the map container
1111
* element will be made full screen. */
1212
containerId?: string;
@@ -16,22 +16,21 @@ export type FullscreenControlProps<OptionsT> = Omit<OptionsT, 'container'> & {
1616
style?: React.CSSProperties;
1717
};
1818

19-
function FullscreenControl<FullscreenControlOptions, ControlT extends FullscreenControlInstance>(
20-
props: FullscreenControlProps<FullscreenControlOptions>
21-
): null {
22-
const ctrl = useControl<ControlT>(
19+
function _FullscreenControl(props: FullscreenControlProps) {
20+
const ctrl = useControl(
2321
({mapLib}) =>
2422
new mapLib.FullscreenControl({
2523
container: props.containerId && document.getElementById(props.containerId)
26-
}) as ControlT,
24+
}),
2725
{position: props.position}
2826
);
2927

3028
useEffect(() => {
29+
// @ts-expect-error accessing private member
3130
applyReactStyle(ctrl._controlContainer, props.style);
3231
}, [props.style]);
3332

3433
return null;
3534
}
3635

37-
export default memo(FullscreenControl);
36+
export const FullscreenControl = memo(_FullscreenControl);
Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,68 @@
11
import * as React from 'react';
22
import {useImperativeHandle, useRef, useEffect, forwardRef, memo} from 'react';
33
import {applyReactStyle} from '../utils/apply-react-style';
4-
import useControl from './use-control';
4+
import {useControl} from './use-control';
55

66
import type {
77
ControlPosition,
88
GeolocateControlInstance,
9-
GeolocateEvent,
10-
GeolocateResultEvent,
11-
GeolocateErrorEvent
12-
} from '../types';
9+
GeolocateControlOptions
10+
} from '../types/lib';
11+
import type {GeolocateEvent, GeolocateResultEvent, GeolocateErrorEvent} from '../types/events';
1312

14-
export type GeolocateControlProps<
15-
OptionsT,
16-
ControlT extends GeolocateControlInstance
17-
> = OptionsT & {
13+
export type GeolocateControlProps = GeolocateControlOptions & {
1814
/** Placement of the control relative to the map. */
1915
position?: ControlPosition;
2016
/** CSS style override, applied to the control's container */
2117
style?: React.CSSProperties;
2218

2319
/** Called on each Geolocation API position update that returned as success. */
24-
onGeolocate?: (e: GeolocateResultEvent<ControlT>) => void;
20+
onGeolocate?: (e: GeolocateResultEvent) => void;
2521
/** Called on each Geolocation API position update that returned as an error. */
26-
onError?: (e: GeolocateErrorEvent<ControlT>) => void;
22+
onError?: (e: GeolocateErrorEvent) => void;
2723
/** Called on each Geolocation API position update that returned as success but user position
2824
* is out of map `maxBounds`. */
29-
onOutOfMaxBounds?: (e: GeolocateResultEvent<ControlT>) => void;
25+
onOutOfMaxBounds?: (e: GeolocateResultEvent) => void;
3026
/** Called when the GeolocateControl changes to the active lock state. */
31-
onTrackUserLocationStart?: (e: GeolocateEvent<ControlT>) => void;
27+
onTrackUserLocationStart?: (e: GeolocateEvent) => void;
3228
/** Called when the GeolocateControl changes to the background state. */
33-
onTrackUserLocationEnd?: (e: GeolocateEvent<ControlT>) => void;
29+
onTrackUserLocationEnd?: (e: GeolocateEvent) => void;
3430
};
3531

36-
function GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateControlInstance>(
37-
props: GeolocateControlProps<GeolocateControlOptions, ControlT>,
38-
ref: React.Ref<ControlT>
39-
) {
32+
function _GeolocateControl(props: GeolocateControlProps, ref: React.Ref<GeolocateControlInstance>) {
4033
const thisRef = useRef({props});
4134

42-
const ctrl = useControl<ControlT>(
35+
const ctrl = useControl(
4336
({mapLib}) => {
44-
const gc = new mapLib.GeolocateControl(props) as ControlT;
37+
const gc = new mapLib.GeolocateControl(props);
4538

4639
// Hack: fix GeolocateControl reuse
4740
// When using React strict mode, the component is mounted twice.
4841
// GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.
49-
// @ts-expect-error private method
50-
const setupUI = gc._setupUI;
51-
// @ts-expect-error private method
42+
// @ts-expect-error accessing private method
43+
const setupUI = gc._setupUI.bind(gc);
44+
// @ts-expect-error overriding private method
5245
gc._setupUI = args => {
46+
// @ts-expect-error accessing private member
5347
if (!gc._container.hasChildNodes()) {
5448
setupUI(args);
5549
}
5650
};
5751

5852
gc.on('geolocate', e => {
59-
thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent<ControlT>);
53+
thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent);
6054
});
6155
gc.on('error', e => {
62-
thisRef.current.props.onError?.(e as GeolocateErrorEvent<ControlT>);
56+
thisRef.current.props.onError?.(e as GeolocateErrorEvent);
6357
});
6458
gc.on('outofmaxbounds', e => {
65-
thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent<ControlT>);
59+
thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent);
6660
});
6761
gc.on('trackuserlocationstart', e => {
68-
thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent<ControlT>);
62+
thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent);
6963
});
7064
gc.on('trackuserlocationend', e => {
71-
thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent<ControlT>);
65+
thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent);
7266
});
7367

7468
return gc;
@@ -81,10 +75,11 @@ function GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateCon
8175
useImperativeHandle(ref, () => ctrl, []);
8276

8377
useEffect(() => {
78+
// @ts-expect-error accessing private member
8479
applyReactStyle(ctrl._container, props.style);
8580
}, [props.style]);
8681

8782
return null;
8883
}
8984

90-
export default memo(forwardRef(GeolocateControl));
85+
export const GeolocateControl = memo(forwardRef(_GeolocateControl));

modules/main/src/mapbox-legacy/components/layer.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,29 @@ import {MapContext} from './map';
33
import assert from '../utils/assert';
44
import {deepEqual} from '../utils/deep-equal';
55

6-
import type {MapInstance, CustomLayerInterface, ILayer} from '../types';
6+
import type {MapInstance, CustomLayerInterface} from '../types/lib';
7+
import type {AnyLayer} from '../types/style-spec';
78

89
// Omiting property from a union type, see
910
// https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230
1011
type OptionalId<T> = T extends {id: string} ? Omit<T, 'id'> & {id?: string} : T;
1112
type OptionalSource<T> = T extends {source: string} ? Omit<T, 'source'> & {source?: string} : T;
1213

13-
export type LayerProps<LayerT> = OptionalSource<OptionalId<LayerT>> & {
14+
export type LayerProps = (OptionalSource<OptionalId<AnyLayer>> | CustomLayerInterface) & {
1415
/** If set, the layer will be inserted before the specified layer */
1516
beforeId?: string;
1617
};
1718

1819
/* eslint-disable complexity, max-statements */
19-
function updateLayer<LayerT extends ILayer>(
20-
map: MapInstance,
21-
id: string,
22-
props: LayerProps<LayerT>,
23-
prevProps: LayerProps<LayerT>
24-
) {
20+
function updateLayer(map: MapInstance, id: string, props: LayerProps, prevProps: LayerProps) {
2521
assert(props.id === prevProps.id, 'layer id changed');
2622
assert(props.type === prevProps.type, 'layer type changed');
2723

2824
if (props.type === 'custom' || prevProps.type === 'custom') {
2925
return;
3026
}
3127

28+
// @ts-ignore filter does not exist in some Layer types
3229
const {layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId} = props;
3330

3431
if (beforeId !== prevProps.beforeId) {
@@ -38,29 +35,30 @@ function updateLayer<LayerT extends ILayer>(
3835
const prevLayout = prevProps.layout || {};
3936
for (const key in layout) {
4037
if (!deepEqual(layout[key], prevLayout[key])) {
41-
map.setLayoutProperty(id, key, layout[key]);
38+
map.setLayoutProperty(id, key as any, layout[key]);
4239
}
4340
}
4441
for (const key in prevLayout) {
4542
if (!layout.hasOwnProperty(key)) {
46-
map.setLayoutProperty(id, key, undefined);
43+
map.setLayoutProperty(id, key as any, undefined);
4744
}
4845
}
4946
}
5047
if (paint !== prevProps.paint) {
5148
const prevPaint = prevProps.paint || {};
5249
for (const key in paint) {
5350
if (!deepEqual(paint[key], prevPaint[key])) {
54-
map.setPaintProperty(id, key, paint[key]);
51+
map.setPaintProperty(id, key as any, paint[key]);
5552
}
5653
}
5754
for (const key in prevPaint) {
5855
if (!paint.hasOwnProperty(key)) {
59-
map.setPaintProperty(id, key, undefined);
56+
map.setPaintProperty(id, key as any, undefined);
6057
}
6158
}
6259
}
6360

61+
// @ts-ignore filter does not exist in some Layer types
6462
if (!deepEqual(filter, prevProps.filter)) {
6563
map.setFilter(id, filter);
6664
}
@@ -69,14 +67,10 @@ function updateLayer<LayerT extends ILayer>(
6967
}
7068
}
7169

72-
function createLayer<LayerT extends ILayer>(
73-
map: MapInstance,
74-
id: string,
75-
props: LayerProps<LayerT>
76-
) {
70+
function createLayer(map: MapInstance, id: string, props: LayerProps) {
7771
// @ts-ignore
7872
if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
79-
const options: LayerProps<LayerT> = {...props, id};
73+
const options: LayerProps = {...props, id};
8074
delete options.beforeId;
8175

8276
// @ts-ignore
@@ -88,7 +82,7 @@ function createLayer<LayerT extends ILayer>(
8882

8983
let layerCounter = 0;
9084

91-
function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInterface>) {
85+
export function Layer(props: LayerProps) {
9286
const map = useContext(MapContext).map.getMap();
9387
const propsRef = useRef(props);
9488
const [, setStyleLoaded] = useState(0);
@@ -129,5 +123,3 @@ function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInte
129123

130124
return null;
131125
}
132-
133-
export default Layer;

0 commit comments

Comments
 (0)