11import { get , has , isArray , isEmpty , isObject } from 'lodash-es' ;
2- import { FormItemInstance } from '../FormItem' ;
2+ import type { FormItemInstance } from '../FormItem' ;
33import type { NamePath } from '../type' ;
44
55/**
66 * 在 `formMap` 中查找指定的 `FormItem`
77 * (仅查找当前层级)
88 */
9- export function findFormItem ( name : NamePath , formMapRef : React . MutableRefObject < Map < any , any > > ) {
9+ export function findFormItem (
10+ name : NamePath ,
11+ formMapRef : React . MutableRefObject < Map < any , any > > ,
12+ ) : React . RefObject < FormItemInstance > | undefined {
1013 if ( ! formMapRef . current ) return ;
1114 // 提取所有 map key
1215 const mapKeys = [ ...formMapRef . current . keys ( ) ] ;
1316 // 转译为字符串后比对 key 兼容数组格式
1417 const key = mapKeys . find ( ( key ) => String ( key ) === String ( name ) ) ;
1518 // 拿到 key 引用地址获取 value
16- return formMapRef . current . get ( key ) as React . RefObject < FormItemInstance > ;
19+ return formMapRef . current . get ( key ) ;
1720}
1821
1922/**
@@ -24,8 +27,8 @@ export function findFormItemDeep(
2427 name : NamePath ,
2528 formMapRef : React . MutableRefObject < Map < any , any > > ,
2629 depth = 0 ,
27- ) : React . RefObject < FormItemInstance > | null {
28- if ( ! formMapRef ?. current ) return null ;
30+ ) : React . RefObject < FormItemInstance > | undefined {
31+ if ( ! formMapRef ?. current ) return ;
2932 const targetPath = Array . isArray ( name ) ? name : [ name ] ;
3033 for ( const [ key , ref ] of formMapRef . current . entries ( ) ) {
3134 const formItem = ref ?. current ;
@@ -38,7 +41,6 @@ export function findFormItemDeep(
3841 const found = findFormItemDeep ( name , formListMapRef , depth + 1 ) ;
3942 if ( found ) return found ;
4043 }
41- return null ;
4244}
4345
4446// { user: { name: '' } } => [['user', 'name']]
0 commit comments