From f39e1d96e8ca393b24f7b9772e9dbda98ae3bb65 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Wed, 26 Feb 2025 05:00:33 +1100 Subject: [PATCH] [TS] Use strict mode in LLink & Reroute (#602) - Adds fallback colour if reroute colour is somehow nullish --- src/LGraphNode.ts | 2 +- src/LLink.ts | 13 ++++++++----- src/Reroute.ts | 26 ++++++++++++++++---------- src/interfaces.ts | 4 ++-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index ab89c9dfe..afc2a2636 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -815,7 +815,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { * @param slot * @param data */ - setOutputData(slot: number, data: unknown): void { + setOutputData(slot: number, data: number | string | boolean | { toToolTip?(): string }): void { if (!this.outputs) return // this maybe slow and a niche case diff --git a/src/LLink.ts b/src/LLink.ts index 8fde39c4a..8be1894a4 100644 --- a/src/LLink.ts +++ b/src/LLink.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import type { CanvasColour, LinkNetwork, @@ -46,9 +45,9 @@ export class LLink implements LinkSegment, Serialisable { /** @inheritdoc */ _centreAngle?: number - #color?: CanvasColour + #color?: CanvasColour | null /** Custom colour for this link only */ - public get color(): CanvasColour { + public get color(): CanvasColour | null | undefined { return this.#color } @@ -108,7 +107,9 @@ export class LLink implements LinkSegment, Serialisable { network: LinkNetwork, linkSegment: LinkSegment, ): Reroute[] { - return network.reroutes.get(linkSegment.parentId) + if (!linkSegment.parentId) return [] + return network.reroutes + .get(linkSegment.parentId) ?.getReroutes() ?? [] } @@ -125,7 +126,9 @@ export class LLink implements LinkSegment, Serialisable { linkSegment: LinkSegment, rerouteId: RerouteId, ): Reroute | null | undefined { - return network.reroutes.get(linkSegment.parentId) + if (!linkSegment.parentId) return + return network.reroutes + .get(linkSegment.parentId) ?.findNextReroute(rerouteId) } diff --git a/src/Reroute.ts b/src/Reroute.ts index 520086a4f..18ff5da4c 100644 --- a/src/Reroute.ts +++ b/src/Reroute.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import type { CanvasColour, LinkSegment, @@ -31,12 +30,12 @@ export class Reroute implements Positionable, LinkSegment, Serialisable