From 5bf32706ba2277275fb754ae6f69b6bee61afe5f Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 17 Jun 2024 12:16:23 +0900 Subject: [PATCH] fix type --- .eslintrc.js | 2 +- src/views/nodes.ts | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fa76b78..32ce1da 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,7 +11,7 @@ module.exports = { rules: { "vue/no-unused-vars": "error", "vue/no-reserved-component-names": "error", - "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": "error", "no-unreachable": "error", "vue/multi-word-component-names": "off", diff --git a/src/views/nodes.ts b/src/views/nodes.ts index d72ed72..6615fb3 100644 --- a/src/views/nodes.ts +++ b/src/views/nodes.ts @@ -1,18 +1,14 @@ import { LGraphNode } from "litegraph.js"; -type Methods = { - [key: string]: (...args: any[]) => any; -}; - type AgentData = { cname: string; name: string; - inputs?: [string, string][]; - outputs?: [string, string][]; + inputs?: string[][]; + outputs?: string[][]; }; -function createAgentNode(agentData: AgentData, baseClass: { new (...args: any[]): any }) { +function createAgentNode(agentData: AgentData) { class DynamicSubclass extends LGraphNode { - constructor(...args: any[]) { + constructor() { super(agentData.name); (this as any).className = agentData.cname; if (agentData.inputs) { @@ -31,11 +27,10 @@ function createAgentNode(agentData: AgentData, baseClass: { new (...args: any[]) Object.defineProperty(DynamicSubclass, "name", { value: agentData.cname }); - return DynamicSubclass as new (...args: any[]) => { className: string } & LGraphNode; + return DynamicSubclass; } -const ret = {}; -[ +const ret = [ { cname: "BasicSumAgent", name: "Sum", @@ -71,7 +66,8 @@ const ret = {}; }, { cname: "StringTemplateAgentNode", name: "StringTemplate", inputs: [["${0}", "string"]], outputs: [["Output", "string"]] }, { cname: "PropertyFilterAgentNode", name: "PropertyFilter", inputs: [["In", "string"]], outputs: [["Output", "string"]] }, -].map((agent: AgentData) => { - ret[agent.cname] = createAgentNode(agent, LGraphNode); -}); -export default ret; +].reduce((tmp: Record LGraphNode>, agent: AgentData) => { + tmp[agent.cname] = createAgentNode(agent); + return tmp; +}, {}); +export default ret;