Skip to content

Commit 34bfc23

Browse files
committed
Add @types/topojson-client for TypeScript support
1 parent 650d208 commit 34bfc23

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

exec/java-exec/src/main/resources/webapp/package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exec/java-exec/src/main/resources/webapp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@types/react-dom": "^18.2.18",
5050
"@types/react-grid-layout": "^1.3.5",
5151
"@types/regression": "^2.0.6",
52+
"@types/topojson-client": "^3.1.5",
5253
"@typescript-eslint/eslint-plugin": "^6.15.0",
5354
"@typescript-eslint/parser": "^6.15.0",
5455
"@vitejs/plugin-react": "^4.2.1",

exec/java-exec/src/main/resources/webapp/src/api/geojson.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function fetchGeoJson(mapId: string): Promise<object> {
3939
// If it's TopoJSON, convert to GeoJSON
4040
if ('objects' in data) {
4141
console.debug(`[GeoJSON] Converting TopoJSON to GeoJSON for ${mapId}`);
42-
return convertTopoJsonToGeoJson(data as topojson.Topology);
42+
return convertTopoJsonToGeoJson(data as unknown);
4343
}
4444

4545
return data;
@@ -83,20 +83,25 @@ async function tryFetchMap(mapId: string, ext: string): Promise<unknown> {
8383
}
8484
}
8585

86-
function convertTopoJsonToGeoJson(
87-
topoData: topojson.Topology
88-
): Record<string, unknown> {
86+
function convertTopoJsonToGeoJson(topoData: unknown): object {
8987
try {
88+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
89+
const topo = topoData as any;
90+
if (!topo.objects) {
91+
throw new Error('Invalid TopoJSON: missing objects property');
92+
}
93+
9094
// Get the first object from the topology (usually 'features' or a similar key)
91-
const objectKey = Object.keys(topoData.objects)[0];
95+
const objectKey = Object.keys(topo.objects)[0];
9296
if (!objectKey) {
9397
throw new Error('TopoJSON has no objects');
9498
}
9599

96100
// Convert the topology object to GeoJSON FeatureCollection
97-
const geoJson = topojson.feature(topoData, topoData.objects[objectKey]);
101+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
102+
const geoJson = topojson.feature(topo, topo.objects[objectKey]) as any;
98103
console.debug(`[GeoJSON] Converted TopoJSON with key "${objectKey}"`);
99-
return geoJson;
104+
return geoJson as object;
100105
} catch (error) {
101106
console.error(`[GeoJSON] TopoJSON conversion failed:`, error);
102107
throw new Error(`Failed to convert TopoJSON: ${error}`);

0 commit comments

Comments
 (0)