api-typings
api-typings copied to clipboard
[Bug]selectAll和select两个选择器的返回值应该是不一样的
环境
- api-typings 版本:3.3.2
- 系统版本:macos 10.14.6
- ide: vscode 1.57.0
问题
在使用 selectAll时,boundingClientRect cb 里面的 results 是个对象,而不是数组。
wx.createSelectorQuery().selectAll('.a-class').boundingClientRect(function(rects){
rects // d.ts 内是个对象而不是数组
}).exec()
证明它是个问题
根据小程序文档可知:
wx.createSelectorQuery().select.boundingClientRect(cb)
和
wx.createSelectorQuery().selectAll.boundingClientRect(cb)
内的cb类型实际上是不同的。
前者内的 cb 类型类似这样
(result: BoundingClientRectCallbackResult) => void
而后者的cb类型应该是这样
(results: BoundingClientRectCallbackResult[]) => void
但是在 lib.wx.api.d.ts中,返回的都是 NodesRef 类型,没有区分对象和集合
select(
/** 选择器 */
selector: string
): NodesRef
selectAll(
/** 选择器 */
selector: string
): NodesRef
同 #194 #195 这两个问题。但它们似乎没有更多的下文了,就新开一个 issues 描述的详细一点
这个接口设计得不是很 ts……手动改好像容易些,基于现在从文档生成的流程好像有些困难,我看看是不是先改成 result | result[] 做个 workaround
加个泛型呗
满屏as 莫不如result[] 的时候强制 as unknown as result[]了
+1
2023年了, 问题依旧, 请问至少有没有什么可接受点的workaround? 靠<WechatMiniprogram.BoundingClientRectCallbackResult[]><unknown>总有点 satisfy complier only 的感觉