From 1dedce5ec6ead0567ab6e1e012f90e6721d3bd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20S=C3=B6derqvist?= Date: Fri, 25 Oct 2024 21:42:15 +0200 Subject: [PATCH] Enable ts-strict for colorUtil, contextMenuFilter and linkRenderMode (#1313) * Add types for colorUtil.ts * Add types for contextMenuFilter * Add types to linkRenderMode.ts --- src/extensions/core/contextMenuFilter.ts | 9 ++++----- src/extensions/core/linkRenderMode.ts | 13 ++++++------- src/utils/colorUtil.ts | 8 +++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/extensions/core/contextMenuFilter.ts b/src/extensions/core/contextMenuFilter.ts index f96f2a5d6..afa954e76 100644 --- a/src/extensions/core/contextMenuFilter.ts +++ b/src/extensions/core/contextMenuFilter.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { LiteGraph, LGraphCanvas } from '@comfyorg/litegraph' import { app } from '../../scripts/app' @@ -33,14 +32,14 @@ const ext = { const clickedComboValue = currentNode.widgets ?.filter( (w) => - w.type === 'combo' && w.options.values.length === values.length + w.type === 'combo' && w.options.values?.length === values.length ) .find((w) => - w.options.values.every((v, i) => v === values[i]) + w.options.values?.every((v, i) => v === values[i]) )?.value let selectedIndex = clickedComboValue - ? values.findIndex((v) => v === clickedComboValue) + ? values.findIndex((v: string) => v === clickedComboValue) : 0 if (selectedIndex < 0) { selectedIndex = 0 @@ -122,7 +121,7 @@ const ext = { // When filtering, recompute which items are visible for arrow up/down and maintain selection. displayedItems = items.filter((item) => { const isVisible = - !term || item.textContent.toLocaleLowerCase().includes(term) + !term || item.textContent?.toLocaleLowerCase().includes(term) item.style.display = isVisible ? 'block' : 'none' return isVisible }) diff --git a/src/extensions/core/linkRenderMode.ts b/src/extensions/core/linkRenderMode.ts index aed8a2372..e8e58acaa 100644 --- a/src/extensions/core/linkRenderMode.ts +++ b/src/extensions/core/linkRenderMode.ts @@ -1,10 +1,9 @@ -// @ts-strict-ignore -import { app } from '../../scripts/app' +import { app, ComfyApp } from '../../scripts/app' import { LiteGraph } from '@comfyorg/litegraph' const id = 'Comfy.LinkRenderMode' const ext = { name: id, - async setup(app) { + async setup(app: ComfyApp) { app.ui.settings.addSetting({ id, category: ['Comfy', 'Graph', 'LinkRenderMode'], @@ -12,10 +11,10 @@ const ext = { defaultValue: 2, type: 'combo', options: [ - { value: LiteGraph.STRAIGHT_LINK, text: 'Straight' }, - { value: LiteGraph.LINEAR_LINK, text: 'Linear' }, - { value: LiteGraph.SPLINE_LINK, text: 'Spline' }, - { value: LiteGraph.HIDDEN_LINK, text: 'Hidden' } + { value: LiteGraph.STRAIGHT_LINK.toString(), text: 'Straight' }, + { value: LiteGraph.LINEAR_LINK.toString(), text: 'Linear' }, + { value: LiteGraph.SPLINE_LINK.toString(), text: 'Spline' }, + { value: LiteGraph.HIDDEN_LINK.toString(), text: 'Hidden' } ], onChange(value: number) { app.canvas.links_render_mode = +value diff --git a/src/utils/colorUtil.ts b/src/utils/colorUtil.ts index 162f30052..75e8622a4 100644 --- a/src/utils/colorUtil.ts +++ b/src/utils/colorUtil.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { memoize } from 'lodash' type RGB = { r: number; g: number; b: number } @@ -17,12 +16,11 @@ function rgbToHsl({ r, g, b }: RGB): HSL { b /= 255 const max = Math.max(r, g, b), min = Math.min(r, g, b) - let h: number, s: number + let h = 0, + s = 0 const l: number = (max + min) / 2 - if (max === min) { - h = s = 0 // achromatic - } else { + if (max !== min) { const d = max - min s = l > 0.5 ? d / (2 - max - min) : d / (max + min) switch (max) {