[PR #27051] Fix type-check error #31650

Closed
opened 2026-02-21 20:49:52 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/27051

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix #27050

PR Summary

TypeScript Type Errors Fixed

This commit resolves multiple TypeScript compilation errors and code quality issues:


1. Fix schema type definition passing error

File: web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx

Issue:

  • Code attempted to destructure non-existent getMatchedSchemaType method from useMatchSchemaType()
  • getVarType function expects schemaTypeDefinitions parameter, not a function

Fix:

// Before
const { getMatchedSchemaType } = useMatchSchemaType()
getMatchedSchemaType: (obj) => getMatchedSchemaType(obj, schemaTypeDefinitions)

// After
const { schemaTypeDefinitions } = useMatchSchemaType()
schemaTypeDefinitions

2. Fix optional chaining for potentially undefined object

File: web/app/components/workflow/nodes/http/use-config.ts

Issue: Accessing property of potentially undefined object

Fix:

// Before
const defaultConfig = useStore(s => s.nodesDefaultConfigs).[payload.type]

// After
const defaultConfig = useStore(s => s.nodesDefaultConfigs?.[payload.type])

3. Add missing type definition

File: web/app/components/workflow/nodes/code/types.ts

Issue: CodeDependency type was not defined

Fix: Added type definition

export type CodeDependency = {
  name: string
  version?: string
}

4. Fix React.cloneElement type mismatch

File: web/app/components/workflow/nodes/_base/node.tsx

Issue: Props passed to cloneElement had type mismatch

Fix: Define explicit child component props type

type NodeChildProps = {
  id: string
  data: NodeProps['data']
}

type BaseNodeProps = {
  children: ReactElement<Partial<NodeChildProps>>
  id: NodeProps['id']
  data: NodeProps['data']
}

5. Add DataSourceDefaultValue type support

Files:

  • web/app/components/workflow/hooks/use-nodes-interactions.ts
  • web/app/components/workflow/nodes/_base/components/node-handle.tsx
  • web/app/components/workflow/nodes/_base/components/panel-operator/change-block.tsx

Issue: Function signatures didn't support DataSourceDefaultValue type

Fix: Updated type signatures

// Import type
import type { DataSourceDefaultValue, ToolDefaultValue } from '../block-selector/types'

// Update function signature
handleNodeChange(
  currentNodeId: string,
  nodeType: BlockEnum,
  sourceHandle: string,
  toolDefaultValue?: ToolDefaultValue | DataSourceDefaultValue,
)

6. Fix React Hooks issues

File: web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts

Issues:

  • Missing trailing newline
  • Incomplete useMemo dependency array
  • Variables computed outside useMemo causing closure issues

Fix:

// Fix useVarColor dependency array
}, [variables, isExceptionVariable, variableCategory])

// Refactor useVarName to move all computation inside useMemo
const varName = useMemo(() => {
  let variableFullPathName = variables.slice(1).join('.')
  // ... all computation logic
  return `${isSystem ? 'sys.' : ''}${varName}`
}, [variables, notShowFullPath])

7. Remove duplicate object property

File: web/app/components/workflow/nodes/_base/components/input-var-type-icon.tsx

Issue: Object literal contained duplicate InputVarType.checkbox property

Fix: Removed the second duplicate property definition


Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/27051 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary fix #27050 ## PR Summary ### TypeScript Type Errors Fixed This commit resolves multiple TypeScript compilation errors and code quality issues: --- ### 1. **Fix schema type definition passing error** **File**: `web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx` **Issue**: - Code attempted to destructure non-existent `getMatchedSchemaType` method from `useMatchSchemaType()` - `getVarType` function expects `schemaTypeDefinitions` parameter, not a function **Fix**: ```typescript // Before const { getMatchedSchemaType } = useMatchSchemaType() getMatchedSchemaType: (obj) => getMatchedSchemaType(obj, schemaTypeDefinitions) // After const { schemaTypeDefinitions } = useMatchSchemaType() schemaTypeDefinitions ``` --- ### 2. **Fix optional chaining for potentially undefined object** **File**: `web/app/components/workflow/nodes/http/use-config.ts` **Issue**: Accessing property of potentially `undefined` object **Fix**: ```typescript // Before const defaultConfig = useStore(s => s.nodesDefaultConfigs).[payload.type] // After const defaultConfig = useStore(s => s.nodesDefaultConfigs?.[payload.type]) ``` --- ### 3. **Add missing type definition** **File**: `web/app/components/workflow/nodes/code/types.ts` **Issue**: `CodeDependency` type was not defined **Fix**: Added type definition ```typescript export type CodeDependency = { name: string version?: string } ``` --- ### 4. **Fix React.cloneElement type mismatch** **File**: `web/app/components/workflow/nodes/_base/node.tsx` **Issue**: Props passed to `cloneElement` had type mismatch **Fix**: Define explicit child component props type ```typescript type NodeChildProps = { id: string data: NodeProps['data'] } type BaseNodeProps = { children: ReactElement<Partial<NodeChildProps>> id: NodeProps['id'] data: NodeProps['data'] } ``` --- ### 5. **Add DataSourceDefaultValue type support** **Files**: - `web/app/components/workflow/hooks/use-nodes-interactions.ts` - `web/app/components/workflow/nodes/_base/components/node-handle.tsx` - `web/app/components/workflow/nodes/_base/components/panel-operator/change-block.tsx` **Issue**: Function signatures didn't support `DataSourceDefaultValue` type **Fix**: Updated type signatures ```typescript // Import type import type { DataSourceDefaultValue, ToolDefaultValue } from '../block-selector/types' // Update function signature handleNodeChange( currentNodeId: string, nodeType: BlockEnum, sourceHandle: string, toolDefaultValue?: ToolDefaultValue | DataSourceDefaultValue, ) ``` --- ### 6. **Fix React Hooks issues** **File**: `web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts` **Issues**: - Missing trailing newline - Incomplete `useMemo` dependency array - Variables computed outside `useMemo` causing closure issues **Fix**: ```typescript // Fix useVarColor dependency array }, [variables, isExceptionVariable, variableCategory]) // Refactor useVarName to move all computation inside useMemo const varName = useMemo(() => { let variableFullPathName = variables.slice(1).join('.') // ... all computation logic return `${isSystem ? 'sys.' : ''}${varName}` }, [variables, notShowFullPath]) ``` --- ### 7. **Remove duplicate object property** **File**: `web/app/components/workflow/nodes/_base/components/input-var-type-icon.tsx` **Issue**: Object literal contained duplicate `InputVarType.checkbox` property **Fix**: Removed the second duplicate property definition --- <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ## Screenshots | Before | After | |--------|-------| | ... | ... | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:49:52 -05:00
yindo closed this issue 2026-02-21 20:49:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31650