Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix the effects of IFormProps losing generic type #1418

Merged
merged 2 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/shared/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
isVoidFieldState,
} from './checkers'

const createForm = <T extends Record<any, any> = any>(
const createForm = <T extends object = any>(
options?: IFormProps<T>
) => {
return new Form(options)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export type IFormState<T extends Record<any, any> = any> = Partial<

export type IFormGraph = Record<string, IGeneralFieldState | IFormState>

export interface IFormProps<T = any> {
export interface IFormProps<T extends object = any> {
values?: Partial<T>
initialValues?: Partial<T>
pattern?: FormPatternTypes
Expand All @@ -224,7 +224,7 @@ export interface IFormProps<T = any> {
disabled?: boolean
readOnly?: boolean
readPretty?: boolean
effects?: (form: Form) => void
effects?: (form: Form<T>) => void
validateFirst?: boolean
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Form } from '@formily/core/esm/models'
import { useContext } from 'react'
import { FormContext } from '../shared'

export const useForm = <T extends Record<any, any>>(): Form<T> => {
export const useForm = <T extends object = any>(): Form<T> => {
const form = useContext(FormContext)
if (!form) {
throw new Error('Can not found form instance from context.')
Expand Down