From 11098f7f9b29d4c48051d96efb18b3284278f93d Mon Sep 17 00:00:00 2001 From: snomiao Date: Sun, 17 Aug 2025 09:54:28 +0000 Subject: [PATCH] [bugfix] Fix #private field conflicts in generated types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove #private field declarations from generated .d.ts files to prevent TypeScript compatibility issues when using @comfyorg/comfyui-frontend-types alongside @comfyorg/litegraph packages. Fixes #5033 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../issue-5033-type-compatibility.test.ts | 38 +++++++++++++++++++ vite.types.config.mts | 13 ++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests-ui/tests/issue-5033-type-compatibility.test.ts diff --git a/tests-ui/tests/issue-5033-type-compatibility.test.ts b/tests-ui/tests/issue-5033-type-compatibility.test.ts new file mode 100644 index 0000000000..d8096f7fb7 --- /dev/null +++ b/tests-ui/tests/issue-5033-type-compatibility.test.ts @@ -0,0 +1,38 @@ +/** + * Test for issue #5033: Type compatibility between comfyui-frontend-types and @comfyorg/litegraph + * + * This test verifies that the generated types from this package can be used alongside + * external litegraph types without causing "#private field" conflicts. + */ +import { describe, expect, it } from 'vitest' + +import type { LGraph, LLink } from '@/lib/litegraph/src/litegraph' +import type { ComfyApp } from '@/scripts/app' + +describe('Issue #5033: Type compatibility', () => { + it('should allow ComfyApp.graph to be assigned to LGraph type', () => { + // This test verifies that the types are compatible after removing #private fields + // from the generated .d.ts files + + function getGraph(app: ComfyApp): LGraph { + // This should not cause TypeScript errors about #private field conflicts + return app.graph + } + + // Type test - if this compiles, the issue is fixed + expect(typeof getGraph).toBe('function') + }) + + it('should allow graph.links to be compatible with LLink type', () => { + type LGraphFromApp = ComfyApp['graph'] + + function getLinks(app: ComfyApp): LLink | null { + const graph: LGraphFromApp = app.graph + // This should not cause TypeScript errors about #private field conflicts + return graph.links.get(0) ?? null + } + + // Type test - if this compiles, the issue is fixed + expect(typeof getLinks).toBe('function') + }) +}) diff --git a/vite.types.config.mts b/vite.types.config.mts index 531708909c..78e497e79c 100644 --- a/vite.types.config.mts +++ b/vite.types.config.mts @@ -18,7 +18,18 @@ export default defineConfig({ dts({ copyDtsFiles: true, rollupTypes: true, - tsconfigPath: 'tsconfig.types.json' + tsconfigPath: 'tsconfig.types.json', + beforeWriteFile: (filePath, content) => { + // Remove #private field declarations to prevent conflicts with external packages + // This fixes issue #5033 where #private fields cause type incompatibility + const cleanedContent = content + .replace(/\s*#private;\s*/g, '') // Remove "#private;" declarations + .replace(/\s*#[a-zA-Z_$][a-zA-Z0-9_$]*\s*:\s*[^;]+;\s*/g, '') // Remove full private field declarations + return { + filePath, + content: cleanedContent + } + } }) ] })