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

UseForm API needs to add a generic as form data’s type #21195

Closed
1 task
WinmezzZ opened this issue Feb 3, 2020 · 10 comments
Closed
1 task

UseForm API needs to add a generic as form data’s type #21195

WinmezzZ opened this issue Feb 3, 2020 · 10 comments
Labels
4.x In Ant Design 4.0 improvement improve some features Inactive

Comments

@WinmezzZ
Copy link
Contributor

WinmezzZ commented Feb 3, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

Calling values in the callback to the validateFields method using the form instance returned by useForm() does not require a double assertion or simply forces as to be any type to override its default type Store {[x: string]: any}

What does the proposed API look like?

interface Values {
  name: string
  age: number
}

const DemoForm: FC = () => {
  // before
  // const [form] = Form.useForm()
  // after
  const [form] = Form.useForm<Values>()
  // ...
}
@zombieJ
Copy link
Member

zombieJ commented Feb 3, 2020

ref react-component/field-form#70

@zombieJ zombieJ added 4.x In Ant Design 4.0 improvement improve some features labels Feb 3, 2020
@Kamahl19
Copy link
Contributor

This should also be able without the use of Form.useForm. It would look like

<Form<FormValues> onFinish={}>
</Form>

This works since TypeScript 2.9 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements

@maasencioh
Copy link

There's any way to work on this?

@alejandro-macari
Copy link

This should also be able without the use of Form.useForm. It would look like

<Form<FormValues> onFinish={}>
</Form>

This works since TypeScript 2.9 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements

This is not working and is not a proper solutions for the issue

@saostad
Copy link

saostad commented Jun 29, 2020

This should also be able without the use of Form.useForm. It would look like

<Form<FormValues> onFinish={}>
</Form>

This works since TypeScript 2.9 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements

This is not working and is not a proper solutions for the issue

that was a suggestion not an actual solution!

@suncunhu
Copy link

Have a deadline for solving this problem?

@zombieJ
Copy link
Member

zombieJ commented Jul 14, 2020

@suncunhu, currently typescript do not support generic with HOC that means we can not provide this ability since Form component use forwardRef which block the generic.

Pls feel free to contribute if you have the solution.

@JensDll
Copy link

JensDll commented Aug 4, 2020

Is this ready to be used somehow? Ant Design 4.5.2 still seems to be using the 1.8.0 rc-field-form version.

@zombieJ
Copy link
Member

zombieJ commented Aug 5, 2020

@JensD98 antd release minor version each end of month

@acfasj
Copy link
Contributor

acfasj commented Oct 19, 2020

@JensD98 antd release minor version each end of month

why form.validateFields(); not work, still get the type Store not the generic type I defined. see codesandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x In Ant Design 4.0 improvement improve some features Inactive
Projects
None yet
Development

No branches or pull requests

10 participants