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

setFieldsValue bug with union type of Array and null #43305

Closed
AndreiTS opened this issue Jun 30, 2023 · 12 comments · Fixed by react-component/field-form#599 · May be fixed by react-component/field-form#600
Closed

setFieldsValue bug with union type of Array and null #43305

AndreiTS opened this issue Jun 30, 2023 · 12 comments · Fixed by react-component/field-form#599 · May be fixed by react-component/field-form#600

Comments

@AndreiTS
Copy link

AndreiTS commented Jun 30, 2023

Reproduction link

I cannot reproduce this on codesanbox, probably because it's using a different typescript version, so I'm using
TypeScript playground

Steps to reproduce

Open TypeScript playground link and check the error.

What is expected?

Is expected that setFieldsValue supports properties of type Array | null

What is actually happening?

setFielsValue errors on properties of type Array | null

Environment Info
antd 5.6.3
React 18.2.0
TypeScrpt 5.1.6
System Windows 11
Browser Firefox 102
@afc163
Copy link
Member

afc163 commented Jun 30, 2023

Try to reproduce by forking https://codesandbox.io/s/quizzical-carson-z4kjnl and change typescript version in package.json

@afc163 afc163 added the 🤔 Need Reproduce We cannot reproduce your problem label Jun 30, 2023
@github-actions
Copy link
Contributor

Hello @AndreiTS. Please provide a online reproduction by forking codesandbox of [email protected] or [email protected], or provide a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

你好 @AndreiTS, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击这里创建一个 [email protected][email protected] 的 codesandbox,或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。

@AndreiTS
Copy link
Author

@afc163 here is a minimal reproduction: https://github.com/AndreiTS/antd-setFieldsValue-typescript

image
image

this problem occurs because of this RecursivePartial implementation:
image

@afc163 afc163 removed 🤔 Need Reproduce We cannot reproduce your problem unconfirmed labels Jul 1, 2023
@afc163
Copy link
Member

afc163 commented Jul 1, 2023

react-component/field-form#592 @kiner-tang 帮忙看看

@kiner-tang
Copy link
Member

react-component/field-form#592 @kiner-tang 帮忙看看

我看看

@AndreiTS
Copy link
Author

AndreiTS commented Jul 3, 2023

@kiner-tang changing any to T is better but don't fix the original issue: typescript playground

@kiner-tang
Copy link
Member

kiner-tang commented Jul 3, 2023

@kiner-tang changing any to T is better but don't fix the original issue: typescript playground

That's because strictNullChecks is turned on by default, so you can turn it off and try again.
image

image image

@AndreiTS
Copy link
Author

AndreiTS commented Jul 3, 2023

Could you support this option? It's turned on by default, and enabled is TypeScript is on strict mode

@kiner-tang
Copy link
Member

Could you support this option? It's turned on by default, and enabled is TypeScript is on strict mode

If you want to keep this option on, wouldn't it be better not to use 'null' in the type definition? You can use other types instead. This is due to strictNullChecks in Typescript, not our RecursivePartial tool

@AndreiTS
Copy link
Author

AndreiTS commented Jul 3, 2023

Yes, I can. I actually replaced all null by undefined in my project where it was complaining, but it is annoying and it's probably going to affect someone else. I think there are other RecursivePartial implementations that could help with this.

@AndreiTS
Copy link
Author

AndreiTS commented Jul 3, 2023

This issue also affects types from libraries:

image
image

In this case the only way to fix is setting strictNullChecks to false, which is not ideal.

@yuki2006
Copy link

Given the issue shown in the example above, I would like to reopen this issue and request a resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants