Skip to content

Commit e63b0dc

Browse files
authored
Fix typescript any casts (#99)
* Fix ts any casts * Fix mlmap anys
1 parent a35ba20 commit e63b0dc

5 files changed

Lines changed: 27 additions & 25 deletions

File tree

‎ui/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ build-protos:
3737
mkdir -p ./src/gen
3838
protoc \
3939
--plugin=protoc-gen-ts_proto=$(CURDIR)/node_modules/.bin/protoc-gen-ts_proto \
40-
--ts_proto_out=esModuleInterop=true,outputServices=generic-definitions,outputClientImpl=false:./src/gen \
40+
--ts_proto_out=esModuleInterop=true,outputServices=generic-definitions,outputClientImpl=false,useExactTypes=false:./src/gen \
4141
--proto_path=../shared/src/main/protobuf \
4242
../shared/src/main/protobuf/*.proto
4343

‎ui/src/components/MLMap.tsx‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Map, {Layer, NavigationControl, Popup, Source} from "react-map-gl/maplibr
33
import "maplibre-gl/dist/maplibre-gl.css";
44
import {format, formatDistanceToNow} from "date-fns";
55
import type {StoredLocation} from "../gen/common.ts";
6-
import {type MapGeoJSONFeature} from "maplibre-gl";
7-
import type {Point} from "geojson";
6+
import type {MapGeoJSONFeature, StyleSpecification} from "maplibre-gl";
7+
import type {FeatureCollection, Feature, Point, LineString} from "geojson";
88
import {Segmented} from "antd";
99
import {useLocalStorage} from "../hooks/use-local-storage.ts";
1010
import styles from "./MLMap.module.css";
@@ -41,14 +41,14 @@ export const MLMap: React.FC<MLMapProps> = ({history, selectedDeviceId, forceRec
4141
return () => clearInterval(interval);
4242
}, []);
4343

44-
const pointData = useMemo(() => {
44+
const pointData: FeatureCollection<Point> = useMemo(() => {
4545
return {
4646
type: "FeatureCollection",
4747
features: history
4848
.filter(h => !!h.location)
4949
.slice(-POINT_LIMIT)
5050
.map((h, index, locations) => ({
51-
type: "Feature",
51+
type: "Feature" as const,
5252
properties: {
5353
lat: h.location!.lat,
5454
lon: h.location!.lon,
@@ -58,19 +58,19 @@ export const MLMap: React.FC<MLMapProps> = ({history, selectedDeviceId, forceRec
5858
isLatest: index === locations.length - 1
5959
},
6060
geometry: {
61-
type: "Point",
61+
type: "Point" as const,
6262
coordinates: [h.location!.lon, h.location!.lat]
6363
}
6464
}))
6565
};
6666
}, [history]);
6767

68-
const lineData = useMemo(() => {
68+
const lineData: Feature<LineString> = useMemo(() => {
6969
return {
70-
type: "Feature",
70+
type: "Feature" as const,
7171
properties: {},
7272
geometry: {
73-
type: "LineString",
73+
type: "LineString" as const,
7474
coordinates: history
7575
.filter(h => !!h.location)
7676
.map(h => [h.location!.lon, h.location!.lat])
@@ -130,7 +130,7 @@ export const MLMap: React.FC<MLMapProps> = ({history, selectedDeviceId, forceRec
130130
zoom: DEFAULT_ZOOM
131131
}}
132132
style={{width: "100%", height: "100%"}}
133-
mapStyle={mapUrl as any}
133+
mapStyle={mapUrl as StyleSpecification | string}
134134
interactiveLayerIds={["history-points"]}
135135
cursor={cursor}
136136
onMouseEnter={() => setCursor("pointer")}
@@ -154,18 +154,18 @@ export const MLMap: React.FC<MLMapProps> = ({history, selectedDeviceId, forceRec
154154
<NavigationControl position="bottom-right"/>
155155

156156
{/* Line */}
157-
<Source type="geojson" data={lineData as any} lineMetrics={true}>
158-
<Layer {...lineStyle(cutoffRatio) as any} />
157+
<Source type="geojson" data={lineData} lineMetrics={true}>
158+
<Layer {...lineStyle(cutoffRatio)} />
159159
</Source>
160160

161161
{/* Points */}
162-
<Source type="geojson" data={pointData as any}>
163-
<Layer {...pointStyle as any} />
162+
<Source type="geojson" data={pointData}>
163+
<Layer {...pointStyle} />
164164
</Source>
165165

166166
{accuracyCircle && (
167167
<Source id="accuracy-zone" type="geojson" data={accuracyCircle}>
168-
<Layer {...accuracyCircleStyle as any} />
168+
<Layer {...accuracyCircleStyle} />
169169
</Source>
170170
)}
171171

‎ui/src/components/MLMapStyles.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import circle from "@turf/circle";
2+
import type {CircleLayerSpecification, FillLayerSpecification, LineLayerSpecification} from "maplibre-gl";
23

34
export const circlePoint = (lat: number, lon: number, accuracy: number) => {
45
if (!accuracy || accuracy < 1) return null;
@@ -9,7 +10,7 @@ export const circlePoint = (lat: number, lon: number, accuracy: number) => {
910
});
1011
};
1112

12-
export const pointStyle = {
13+
export const pointStyle: Omit<CircleLayerSpecification, "source"> = {
1314
id: "history-points",
1415
type: "circle",
1516
paint: {
@@ -26,7 +27,7 @@ export const pointStyle = {
2627
}
2728
};
2829

29-
export const accuracyCircleStyle = {
30+
export const accuracyCircleStyle: Omit<FillLayerSpecification, "source"> = {
3031
id: "accuracy-fill",
3132
type: "fill",
3233
paint: {
@@ -36,13 +37,13 @@ export const accuracyCircleStyle = {
3637
}
3738
};
3839

39-
export const lineStyle = (cutoffRatio: number) => {
40+
export const lineStyle = (cutoffRatio: number): Omit<LineLayerSpecification, "source"> => {
4041
const COLOR_FADED = "rgba(0, 0, 255, 0.05)";
4142
const COLOR_TRANSITION = "rgba(0, 0, 255, 0.2)";
4243
const COLOR_SOLID = "rgba(0, 0, 255, 0.3)";
4344
const FADE_LENGTH = 0.1;
4445

45-
let gradientStops;
46+
let gradientStops: (number | string)[];
4647

4748
if (cutoffRatio <= 0) {
4849
// Full solid
@@ -84,5 +85,5 @@ export const lineStyle = (cutoffRatio: number) => {
8485
...gradientStops
8586
]
8687
}
87-
}
88+
};
8889
};

‎ui/src/hooks/use-admin-client.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export function useAdminClient(refreshInterval: number) {
2828

2929
const fetchLocations = useCallback(async () => {
3030
try {
31+
if (selectedDeviceId == null) return;
3132
const response: ListLocationsResponse = await adminClient.listLocations({
3233
deviceId: selectedDeviceId
33-
} as any);
34+
});
3435
console.log("ListLocationsResponse", response);
3536
setHistory(response.locations);
3637
} catch (e) {
@@ -42,7 +43,7 @@ export function useAdminClient(refreshInterval: number) {
4243
const approveDevice = async (deviceId: string) => {
4344
try {
4445
await adminClient.approveDevice(
45-
{deviceId: deviceId} as any,
46+
{deviceId: deviceId},
4647
);
4748
// Refresh list immediately to show the checkmark/status change
4849
await fetchDevices();
@@ -55,7 +56,7 @@ export function useAdminClient(refreshInterval: number) {
5556
const deleteDevice = async (deviceId: string) => {
5657
try {
5758
await adminClient.deleteDevice(
58-
{deviceId: deviceId} as any,
59+
{deviceId: deviceId},
5960
);
6061
// Refresh list immediately to show the checkmark/status change
6162
await fetchDevices();
@@ -68,7 +69,7 @@ export function useAdminClient(refreshInterval: number) {
6869
const sendNotification = useCallback(async (deviceId: string, notificationType: NotificationType) => {
6970
try {
7071
return await adminClient.sendNotification(
71-
{deviceId: deviceId, notificationType: notificationType} as any,
72+
{deviceId: deviceId, notificationType: notificationType},
7273
);
7374
} catch (e) {
7475
console.error(e);

‎ui/src/hooks/use-login.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function useLogin() {
3838
try {
3939
const response: LoginResponse = await adminClient.login({
4040
password: password
41-
} as any);
41+
});
4242

4343
updateAndStoreToken(response.token, null);
4444
} catch (e) {

0 commit comments

Comments
 (0)