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

Type problem: form.item is not type safe due to not forwarding their type parameters to the rcForm components #29315

Closed
1 task done
dgreene1 opened this issue Feb 10, 2021 · 3 comments · Fixed by #29397
Closed
1 task done
Labels
help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request.

Comments

@dgreene1
Copy link
Contributor

dgreene1 commented Feb 10, 2021

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

Reproduction link

Edit on CodeSandbox

Steps to reproduce

When you visit the reproduction link you'll see:

  1. on line 99 of src/index.tsx that we're getting the error "Expected 0 type arguments, but got 1.ts(2558" since Form.Item is not a generic. It can easily be generic since the rcForm component it wraps is generic. While I do not see this error in my local branch, I do see from looking into the types that Values in FormItemProps<Values = any> is not being passed to the rcFieldForm's FieldProps from which it extends.
  2. Due to those limitations, most of the form functions fallback to the any type. For instance on lines 103-105, Typescript should be erroring but it doesn't have enough information to tell the user that the code won't actually error. Essentially shouldUpdate is very unsafe.

What is expected?

  • shouldUpdate should not pass or return variables of type any if a type parameter is passed to Form.Item. I.e. if I instantiate the component as Form.Item<{aKey: string}> then the type of shouldUpdate should be:
boolean | ((prevValues: {aKey: string}, nextValues: {aKey: string}, info: {
    source?: string | undefined;
}) => boolean) | undefined

What is actually happening?

  • shouldUpdate is of type:
boolean | ((prevValues: any, nextValues: any, info: {
    source?: string | undefined;
}) => boolean) | undefined
Environment Info
antd 4.11.2
React standard react 16.13.1
System Windows/OSX/Linux
Browser all browsers all versions

I caught this via the eslint rule "@typescript-eslint/no-explicit-any"

@dgreene1
Copy link
Contributor Author

dgreene1 commented Feb 10, 2021

I am prepared to send a PR in as soon as this issue is approved to be worked. Please let me know when I can submit the PR.

@afc163 afc163 added the help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request. label Feb 12, 2021
@ant-design-bot
Copy link
Contributor

Hello @dgreene1. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @dgreene1,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

giphy

@mumiao
Copy link
Contributor

mumiao commented Feb 20, 2021

i mention PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants