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

统一基础值类型 #49058

Closed
guaijie opened this issue May 24, 2024 · 21 comments
Closed

统一基础值类型 #49058

guaijie opened this issue May 24, 2024 · 21 comments
Labels
🤔 Need Reproduce We cannot reproduce your problem unconfirmed

Comments

@guaijie
Copy link

guaijie commented May 24, 2024

Reproduction link

复现链接地址

image

Steps to reproduce

@types/react 的 Key 类型修改为 type Key = number | string | bigint

在 antd 中有些组件的值使用的是 React.Key
有的组件值使用的是 string | number

在过去这并没有什么问题,但在最新的版本中因 Key 的类型修改导致在各个组件中进行值传递时会导致类型报错

What is expected?

统一基础值类型,要么都为 number | string(或再联合其他类型) 类型,要么都为 React.Key 的类型(或再联合其他类型)

What is actually happening?

no response

Environment Info
antd 5.17.3
React 18.0.0
System windows
Browser edge 114.0.1823.37
@afc163
Copy link
Member

afc163 commented May 24, 2024

现在 React.Key 里有个 bigint,难受。

@guaijie
Copy link
Author

guaijie commented May 24, 2024

现在 React.Key 里有个 bigint,难受。

我升级类型文件之后,看着报红,又决定回退版本了

@afc163
Copy link
Member

afc163 commented May 24, 2024

具体问题反馈一下,提供一个重现?这样比较好下手。

@afc163 afc163 added the 🤔 Need Reproduce We cannot reproduce your problem label May 24, 2024
Copy link
Contributor

Hello @guaijie. Please provide a online reproduction by forking codesandbox of antd@5.x or antd@4.x, or provide a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

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

什么是最小化重现,为什么这是必需的?

Copy link

stackblitz bot commented May 27, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@crazyair
Copy link
Member

antd v4?

@crazyair
Copy link
Member

fix v5

@guaijie
Copy link
Author

guaijie commented May 27, 2024

@afc163 @crazyair InputNumber 组件不需要支持 bigInt 吗?我那复现只是一个例子

@crazyair
Copy link
Member

@afc163 @crazyair InputNumber 组件不需要支持 bigInt 吗?我那复现只是一个例子

应该都改成泛型的方式,用户想用什么类型,都是用户自己传的

@crazyair
Copy link
Member

@afc163 @crazyair InputNumber 组件不需要支持 bigInt 吗?我那复现只是一个例子

应该都改成泛型的方式,用户想用什么类型,都是用户自己传的

你可以参考 Checkbox 这个对其他组件进行 fix

@guaijie
Copy link
Author

guaijie commented May 27, 2024

@crazyair 是否要对所有支持 number 数据类型的组件都让其支持 bigint 类型?

@crazyair
Copy link
Member

@crazyair 是否要对所有支持 number 数据类型的组件都让其支持 bigint 类型?

不是给类型增加什么类型,而是用 T

@crazyair
Copy link
Member

InputNumberProps<T extends ValueType = ValueType> 这种约束的直接去掉就可以 InputNumberProps<T = any>

@guaijie
Copy link
Author

guaijie commented May 27, 2024

@crazyair 是否要对所有支持 number 数据类型的组件都让其支持 bigint 类型?

不是给类型增加什么类型,而是用 T

我懂你的意思,我想表述的意思是否对所有支持 number 数据类型的组件都改成泛型的形式
image

像这种的话,只支持 number 无可厚非,当然也可以是 bigint , 但改成 T 没有意义
当然还有其他的组件,比如分页

@crazyair
Copy link
Member

@crazyair 是否要对所有支持 number 数据类型的组件都让其支持 bigint 类型?

不是给类型增加什么类型,而是用 T

我懂你的意思,我想表述的意思是否对所有支持 number 数据类型的组件都改成泛型的形式 image

像这种的话,只支持 number 无可厚非,当然也可以是 bigint , 但改成 T 没有意义

这样就属于组件定义的范畴了,如果定死数字类型也不是不可以

@guaijie
Copy link
Author

guaijie commented May 27, 2024

InputNumberProps<T extends ValueType = ValueType> 这种约束的直接去掉就可以 InputNumberProps<T = any>

当然,ValueType = number | bigint | string 这种类型约束,个人感觉更好。any 意味着任意类型 <InputNumber<number[]> /> 显然不合理
当然,这些只是个人看法

@crazyair
Copy link
Member

InputNumberProps<T extends ValueType = ValueType> 这种约束的直接去掉就可以 InputNumberProps<T = any>

当然,ValueType = number | bigint | string 这种类型约束,个人感觉更好。any 意味着任意类型 <InputNumber<number[]> /> 显然不合理

<InputNumber value={1} 如果这样写了,T 就是 number

@guaijie
Copy link
Author

guaijie commented May 27, 2024

InputNumberProps<T extends ValueType = ValueType> 这种约束的直接去掉就可以 InputNumberProps<T = any>

当然,ValueType = number | bigint | string 这种类型约束,个人感觉更好。any 意味着任意类型 <InputNumber<number[]> /> 显然不合理

<InputNumber value={1} 如果这样写了,T 就是 number

我知道,但也意味着 value 可以传递任何值,因为它已经不受约束了

<InputNumber value={[1]},

ts 不会报任何错误。但事实是,组件内部应该会报错(当然,我并没有看源码,所以并不清楚是否真的报错)

@crazyair
Copy link
Member

InputNumberProps<T extends ValueType = ValueType> 这种约束的直接去掉就可以 InputNumberProps<T = any>

当然,ValueType = number | bigint | string 这种类型约束,个人感觉更好。any 意味着任意类型 <InputNumber<number[]> /> 显然不合理

<InputNumber value={1} 如果这样写了,T 就是 number

我知道,但也意味着 value 可以传递任何值,因为它已经不受约束了

<InputNumber value={[1]},

这也不会报任何错误。但事实是,组件内部应该会报错(当然,我并没有看源码,所以并不清楚是否真的报错)

报不报错,其实不是要类型来兜底,有的项目还不是 ts 呢?

@guaijie
Copy link
Author

guaijie commented May 27, 2024

@crazyair 当然,只是你们很多地方都有进行类型约束,比如 select options , option.value 等,你们这样的目的,也是想在使用时就提醒到用户可以支持的类型有哪些。
当然,ts 这玩意本来就增加了库作者的负担,所以,我只是提出个人看法

@afc163
Copy link
Member

afc163 commented May 27, 2024

InputNumber 目前支持不了 bigint,不只是类型的问题,组件能力还不支持。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Need Reproduce We cannot reproduce your problem unconfirmed
Projects
None yet
Development

No branches or pull requests

3 participants