Skip to content

Commit

Permalink
fix: type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Barrior committed Dec 2, 2024
1 parent afbf6d1 commit d79d417
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
11 changes: 5 additions & 6 deletions packages/core-react/src/hooks/useOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Ref, RefObject } from 'react'
import { useImperativeHandle } from 'react'

import { EValidationStatus } from '../constants'
import type { ICoreRef, IScrollToOptions } from '../typings/core.d'
import type { IApiPath } from '../typings/common'
import type { ICoreRef, IScrollToOptions } from '../typings/core'
import type { IRootContext } from '../typings/rootContext'
import { isArray, isString } from '../utils/checking'
import { positionedOffset } from '../utils/dom'
Expand All @@ -20,8 +21,6 @@ export interface IOpenApiParams {
resetValue: ICoreRef['resetValue']
}

type IPaths = string | string[]

/**
* 内部滚动到指定表单项位置方法
* @param formItemElement 表单项 DOM 元素
Expand Down Expand Up @@ -87,7 +86,7 @@ export default function useOpenApi({
/**
* 查找指定表单项
*/
const findItem = useMemoizedFn((paths?: IPaths) => {
const findItem = useMemoizedFn((paths?: IApiPath) => {
const renderers = rootContextRef.current?.rendererStorage
if (renderers && paths) {
const sPath = isArray(paths) ? stringifyPath(paths) : paths
Expand All @@ -98,7 +97,7 @@ export default function useOpenApi({
/**
* 重置错误与警告
*/
const resetError = useMemoizedFn((paths?: IPaths) => {
const resetError = useMemoizedFn((paths?: IApiPath) => {
const renderers = rootContextRef.current?.rendererStorage
if (renderers) {
const pathList = !paths ? Object.keys(renderers) : isString(paths) ? [paths] : paths
Expand All @@ -118,7 +117,7 @@ export default function useOpenApi({
/**
* 滚动到指定位置
*/
const scrollTo = useMemoizedFn((paths?: IPaths, options?: IScrollToOptions) =>
const scrollTo = useMemoizedFn((paths?: IApiPath, options?: IScrollToOptions) =>
internalScrollTo(findItem(paths)?.getRootElement(), getRootElement(), options)
)

Expand Down
2 changes: 2 additions & 0 deletions packages/core-react/src/typings/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export type IDeepReadonly<T> = {

export type IPath = Array<string | number>

export type IApiPath = string | IPath

export interface ICommonProps<S extends ISchema = ISchema> {
// 渲染器 schema
schema: S
Expand Down
7 changes: 4 additions & 3 deletions packages/core-react/src/typings/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ReactNode } from 'react'
import type { ILayout, IValidationStatus } from '../constants'
import type localeStruct from '../locale/zh_CN'
import type {
IApiPath,
IDeepReadonly,
IDictionary,
IMaybePromise,
Expand Down Expand Up @@ -175,7 +176,7 @@ export interface ICoreRef {
/**
* 重置错误信息(含警告信息),当数据回填时,可以用此方法重置错误信息
*/
resetError: (paths?: string | string[]) => void
resetError: (paths?: IApiPath) => void
/**
* 获取表单数据
*/
Expand All @@ -195,13 +196,13 @@ export interface ICoreRef {
/**
* 查找指定表单项,返回表单项实例的开放 API
*/
findItem: (paths?: string | string[]) => IRendererInstance | undefined
findItem: (paths?: IApiPath) => IRendererInstance | undefined
/**
* 滚动到指定表单项
* @param paths 表单项路径
* @param options 滚动参数
*/
scrollTo: (paths?: string | string[], options?: IScrollToOptions) => void
scrollTo: (paths?: IApiPath, options?: IScrollToOptions) => void
}

export interface IRenderers<V extends any = any, S extends ISchema = ISchema> {
Expand Down

0 comments on commit d79d417

Please sign in to comment.