diff --git a/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts b/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts index debf294557..b6b5a43d37 100644 --- a/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts +++ b/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts @@ -6,13 +6,19 @@ import { validateConnectionTypes } from 'features/nodes/store/util/validateConne import type { AnyNode } from 'features/nodes/types/invocation'; import type { Connection as NullableConnection, Edge } from 'reactflow'; import type { O } from 'ts-toolbelt'; +import { assert } from 'tsafe'; type Connection = O.NonNullable; -export type ValidateConnectionResult = { - isValid: boolean; - messageTKey?: string; -}; +export type ValidateConnectionResult = + | { + isValid: true; + messageTKey?: string; + } + | { + isValid: false; + messageTKey: string; + }; export type ValidateConnectionFunc = ( connection: Connection, @@ -22,10 +28,20 @@ export type ValidateConnectionFunc = ( ignoreEdge: Edge | null ) => ValidateConnectionResult; -export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => ({ - isValid, - messageTKey, -}); +export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => { + if (isValid) { + return { + isValid, + messageTKey, + }; + } else { + assert(messageTKey !== undefined); + return { + isValid, + messageTKey, + }; + } +}; const getEqualityPredicate = (c: Connection) =>