[TS] Force explicit override & property access (#1006)

Enables TypeScript rules that improve code legibility.

- Requires `override` keyword
- Prevent indexed properties from being accessed with dot notation

```ts
const obj: Record<string, unknown> = {}

// Prefer
obj["property"]

// Over
obj.property
```
This commit is contained in:
filtered
2025-05-04 06:37:01 +10:00
committed by GitHub
parent f2eafae82d
commit bfc87af9d1
10 changed files with 21 additions and 16 deletions

View File

@@ -48,6 +48,11 @@ export interface LGraphConfig {
links_ontop?: any
}
export interface LGraphExtra extends Dictionary<unknown> {
reroutes?: SerialisableReroute[]
linkExtensions?: { id: number, parentId: number | undefined }[]
}
export interface BaseLGraph {
readonly rootGraph: LGraph
}
@@ -119,7 +124,7 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
nodes_executing: boolean[] = []
nodes_actioning: (string | boolean)[] = []
nodes_executedAction: string[] = []
extra: Record<string, unknown> = {}
extra: LGraphExtra = {}
/** @deprecated Deserialising a workflow sets this unused property. */
version?: number

View File

@@ -6033,7 +6033,7 @@ export class LGraphCanvas {
dialog.close()
} else if (e.key == "Enter") {
if (selected instanceof HTMLElement) {
select(unescape(String(selected.dataset.type)))
select(unescape(String(selected.dataset["type"])))
} else if (first) {
select(first)
} else {
@@ -6395,7 +6395,7 @@ export class LGraphCanvas {
help.className += ` ${className}`
}
help.addEventListener("click", function () {
select(unescape(String(this.dataset.type)))
select(unescape(String(this.dataset["type"])))
})
helper.append(help)
}

View File

@@ -61,9 +61,9 @@ export class LGraphGroup implements Positionable, IPinnable, IColorable {
// TODO: Object instantiation pattern requires too much boilerplate and null checking. ID should be passed in via constructor.
this.id = id ?? -1
this.title = title || "Group"
this.color = LGraphCanvas.node_colors.pale_blue
? LGraphCanvas.node_colors.pale_blue.groupcolor
: "#AAA"
const { pale_blue } = LGraphCanvas.node_colors
this.color = pale_blue ? pale_blue.groupcolor : "#AAA"
}
/** @inheritdoc {@link IColorable.setColorOption} */

View File

@@ -10,7 +10,7 @@ import { LinkDirection } from "@/types/globalEnums"
import { MovingLinkBase } from "./MovingLinkBase"
export class MovingInputLink extends MovingLinkBase {
readonly toType = "input"
override readonly toType = "input"
readonly node: LGraphNode
readonly fromSlot: INodeOutputSlot

View File

@@ -10,7 +10,7 @@ import { LinkDirection } from "@/types/globalEnums"
import { MovingLinkBase } from "./MovingLinkBase"
export class MovingOutputLink extends MovingLinkBase {
readonly toType = "output"
override readonly toType = "output"
readonly node: LGraphNode
readonly fromSlot: INodeInputSlot

View File

@@ -14,7 +14,7 @@ export class ToOutputFromRerouteLink extends ToOutputRenderLink {
network: LinkNetwork,
node: LGraphNode,
fromSlot: INodeInputSlot,
readonly fromReroute: Reroute,
override readonly fromReroute: Reroute,
readonly linkConnector: LinkConnector,
) {
super(network, node, fromSlot, fromReroute)

View File

@@ -21,7 +21,7 @@ export abstract class SubgraphSlot extends SlotBase implements SubgraphIO, Seria
readonly linkIds: LinkId[] = []
readonly boundingRect: Rect = [0, 0, 0, SubgraphSlot.defaultHeight]
override readonly boundingRect: Rect = [0, 0, 0, SubgraphSlot.defaultHeight]
override get pos() {
return this.#pos

View File

@@ -8,7 +8,7 @@ import type {
Point,
Size,
} from "../interfaces"
import type { LGraphConfig, LGraphState } from "../LGraph"
import type { LGraphConfig, LGraphExtra, LGraphState } from "../LGraph"
import type { IGraphGroupFlags } from "../LGraphGroup"
import type { NodeId, NodeProperty } from "../LGraphNode"
import type { LiteGraph } from "../litegraph"
@@ -53,7 +53,7 @@ export interface SerialisableGraph extends BaseExportedGraph {
links?: SerialisableLLink[]
floatingLinks?: SerialisableLLink[]
reroutes?: SerialisableReroute[]
extra?: Dictionary<unknown>
extra?: LGraphExtra
}
export type ISerialisableNodeInput = Omit<INodeInputSlot, "boundingRect" | "widget"> & {
@@ -114,9 +114,7 @@ export interface ISerialisedGraph extends BaseExportedGraph {
floatingLinks?: SerialisableLLink[]
groups: ISerialisedGroup[]
version: typeof LiteGraph.VERSION
extra?: Dictionary<unknown> & {
reroutes?: SerialisableReroute[]
}
extra?: LGraphExtra
}
/**

View File

@@ -36,7 +36,7 @@ export class KnobWidget extends BaseWidget implements IKnobWidget {
}
}
get height(): number {
override get height(): number {
return this.computedHeight || super.height
}

View File

@@ -19,6 +19,8 @@
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"downlevelIteration": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
/* AllowJs during migration phase */
"allowJs": true,