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 + } + } }) ] })