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

AtImagePickerProps与taro hooks兼容性问题 #902

Closed
waiwaic opened this issue Dec 22, 2019 · 4 comments
Closed

AtImagePickerProps与taro hooks兼容性问题 #902

waiwaic opened this issue Dec 22, 2019 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@waiwaic
Copy link

waiwaic commented Dec 22, 2019

问题描述

AtImagePickerProps与taro hooks兼容性问题
复现步骤

// 这里可以贴代码
const [state,setState]=Taro.useState([])
<AtImagePicker onChange={(files)=>setState(files)}></AtImagePicker>

期望行为

是否应当将类型定义修改,还是我的使用方法有误。
报错信息

类型“Object[]”的参数不能赋给类型“SetStateAction<never[]>”的参数。
不能将类型“Object[]”分配给类型“never[]”。
不能将类型“Object”分配给类型“never”。
"Object" 类型可分配给极少数其他类型。是否想要改用“任意”类型?
系统信息

补充信息

interface AtImagePickerProps extends AtComponent {
files: File[]

mode?: 'scaleToFill' | 'aspectFit' | 'aspectFill' | 'widthFix' | 'top' | 'bottom' | 'center' | 'left' | 'right' | 'top left' | 'top right' | 'bottom left' | 'bottom right'

showAddBtn?: boolean

multiple?: boolean

length?: number

count?: number

sizeType?: string[]

sourceType?: string[]

onChange: (files: Array, operationType: string, index: number) => void

onImageClick?: (index: number, file: Object) => void

onFail?: (message: string) => void
}

@taro-ui-bot
Copy link

taro-ui-bot bot commented Dec 22, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Garfield550
Copy link
Collaborator

组件定义里的 Object 类型应该改为更确定的类型,但是 useState 在 TS 下最好显示指定类型,比如 const [isOpend, setIsOpend] = useState<boolean>(false);,特别是在 State 类型为数组或者是复杂对象这种难以自动推导的类型上。

@Garfield550 Garfield550 added the bug Something isn't working label Dec 23, 2019
@waiwaic
Copy link
Author

waiwaic commented Dec 23, 2019

组件定义里的Object类型应该替换为更确定的类型,但是useState在TS下最好显示指定类型,例如const [isOpend, setIsOpend] = useState<boolean>(false);,特别是在State类型为数组或是复杂对象这种难以自动推导的类型上。

如果使用
const state=Taro.useState<Object[]>()
时,因为props.files也是必填字段
不能将类型“Object[]”分配给类型“File[]”。
"Object" 类型可分配给极少数其他类型。是否想要改用“任意”类型?
Property 'url' is missing in type 'Object' but required in type 'File'.
因为 props.files使用的interface是files: File[]所以定义类型也会报错。。。。。。

最后感谢大佬解答

@Garfield550
Copy link
Collaborator

因为确实 onChange 的首个参数错了,应该从 Object[] 改成 File[]

@Garfield550 Garfield550 added this to the Taro UI 2.3.0 milestone Feb 27, 2020
@Garfield550 Garfield550 self-assigned this Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants