Skip to content

Commit 0ae3574

Browse files
committed
update all code to work with typescript 6
Many modules used a pattern that initialized an object with `undefined` placeholders and then patched on real implementations afterwards (e.g. `const self = { add: undefined, render: undefined }; self.add = function(...) {...}`). Under TS 6's strict checking, those properties infer as literal `undefined`, which breaks every later assignment and call site. They were rewritten to either fully built objects (e.g. container.ts, math.ts, forcegraph/draw.ts, utils/node.ts, sidebar.ts, legend.ts, title.ts, tabs.ts, linklist.ts, nodelist.ts, sorttable.ts) or typed stubs + assignments where needed. lib/utils/version.ts: Rewritten as a class so this and new are correctly typed. lib/utils/router.ts: Uses ObjectsLinksAndNodes for objects / setData, safer handling of nodeDict, and routeGroup for regex capture data; Target.gotoNode matches real usage (node, nodeDict). lib/utils/helper.ts: showStat return type fixed to VNode (it always returned a snabbdom VNode; the prior HTMLDivElement type was a cast). lib/forcegraph.ts: Stricter typing for graph state, forceLink.links!(…), MapLink initial x/y, and gotoNode/gotoLink return arrays instead of calling resetView() where a coordinate array is required. lib/proportions.ts: Stubs, GenericFilter vs Filter in watchFilters, gateway modifier return type. lib/infobox/main.ts: Avoids Node / Link name clashes with DOM/utils/node, uses an InfoboxPanel type and as unknown as for panel instances. lib/infobox/link.ts and lib/infobox/node.ts: Same self-initialization pattern fix. node.ts also factors the config-driven dynamic lookup (nodef["show" + value], node[value]) behind named local types (NodeFieldValue, NodefShowers, NodeRecord). lib/map/button.ts (was button.js) and lib/map/locationmarker.ts (was locationmarker.js): Migrated to TypeScript. button.ts names the Leaflet-extend shapes once via ButtonBaseThis / ButtonOnAddThis / ButtonControl / ButtonCtor; the only suppression is a single @ts-expect-error on `Map.locate({setView: "untilPan"})` which Leaflet supports at runtime but @types/leaflet only types as boolean. locationmarker.ts is now a proper ES6 class extending L.CircleMarker.
1 parent bf0f9e5 commit 0ae3574

39 files changed

Lines changed: 1283 additions & 1190 deletions

lib/about.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export const About = function (picturesSource: string, picturesLicense: string):
66
const iconConfig = window.config.icon;
77

88
// apply custom styling from config.json to reflect changes in config.json
9-
const applyColor = (selector: string, key: string) => {
9+
const applyColor = (selector: string, key: keyof typeof iconConfig) => {
1010
// this applies the color config like Leaflet circleMarker config does
1111
const el = d.querySelector(selector) as HTMLElement;
1212
const cfgIcon = iconConfig[key];
1313

14-
el.style.backgroundColor = cfgIcon.fillColor;
15-
el.style.borderColor = cfgIcon.color;
14+
el.style.backgroundColor = cfgIcon.fillColor ?? "";
15+
el.style.borderColor = cfgIcon.color ?? "";
1616
};
1717
applyColor(".legend-new .symbol", "new");
1818
applyColor(".legend-online .symbol", "online");

lib/config_default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export interface Config {
182182
devicePicturesSource: string;
183183
devicePicturesLicense: string;
184184
geo?: Geo[];
185-
fixedCenter: LatLngBoundsExpression;
185+
fixedCenter?: LatLngBoundsExpression;
186186
}
187187

188188
export const config: Config = {

lib/container.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ export const Container = function (tag?: string): CanRender & CanAdd {
1111
tag = "div";
1212
}
1313

14-
const self = {
15-
add: undefined,
16-
render: undefined,
17-
};
18-
19-
let container = document.createElement(tag);
20-
21-
self.add = function add(d: CanRender) {
22-
d.render(container);
23-
};
14+
const container = document.createElement(tag);
2415

25-
self.render = function render(el: HTMLElement) {
26-
el.appendChild(container);
16+
const self: CanRender & CanAdd = {
17+
add(d: CanRender) {
18+
d.render(container);
19+
},
20+
render(el: HTMLElement) {
21+
el.appendChild(container);
22+
},
2723
};
2824

2925
return self;

lib/datadistributor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface GenericFilter extends Filter {
4242
export type FilterMethod = (node: Node) => boolean;
4343

4444
export const DataDistributor = function () {
45-
let targets = [];
45+
let targets: CanSetData[] = [];
4646
let filterObservers: CanFiltersChanged[] = [];
4747
let filters: Filter[] = [];
4848
let filteredData: ObjectsLinksAndNodes;
@@ -103,7 +103,7 @@ export const DataDistributor = function () {
103103
let newItem = true;
104104

105105
filters.forEach(function (oldFilter: Filter) {
106-
if (oldFilter.getKey && oldFilter.getKey() === filter.getKey()) {
106+
if (oldFilter.getKey && filter.getKey && oldFilter.getKey() === filter.getKey()) {
107107
removeFilter(oldFilter);
108108
newItem = false;
109109
}

lib/filters/filtergui.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export const FilterGui = function (distributor: ReturnType<typeof DataDistributo
1111
el.appendChild(div);
1212
}
1313

14-
function filtersChanged(filters: Filter[] & CanRender[]) {
14+
function filtersChanged(filters: Filter[]) {
1515
while (container.firstChild) {
1616
container.removeChild(container.firstChild);
1717
}
1818

19-
filters.forEach(function (filter: Filter & CanRender) {
19+
(filters as (Filter & CanRender)[]).forEach(function (filter) {
2020
let li = document.createElement("li");
2121
container.appendChild(li);
2222
filter.render(li);

lib/filters/hostname.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CanRender } from "../container.js";
44
import { Filter } from "../datadistributor.js";
55

66
export const HostnameFilter = function (): CanRender & Filter {
7-
let refreshFunctions: ((bool?) => any)[] = [];
7+
let refreshFunctions: ((preserveFocus?: boolean) => void)[] = [];
88
let timer: ReturnType<typeof setTimeout>;
99
let input = document.createElement("input");
1010

lib/filters/nodefilter.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ export const NodeFilter = function (filter: FilterMethod) {
55
let node: ObjectsLinksAndNodes = Object.create(data);
66
node.nodes = { all: [], lost: [], new: [], offline: [], online: [] };
77

8-
for (let key in data.nodes) {
9-
if (data.nodes.hasOwnProperty(key)) {
10-
node.nodes[key] = data.nodes[key].filter(filter);
11-
}
8+
const nodeKeys: (keyof import("../datadistributor.js").NodesByState)[] = [
9+
"all",
10+
"lost",
11+
"new",
12+
"offline",
13+
"online",
14+
];
15+
for (const key of nodeKeys) {
16+
node.nodes[key] = data.nodes[key].filter(filter);
1217
}
1318

1419
node.links = data.links.filter(function (d) {

0 commit comments

Comments
 (0)