wechat-miniprogram / wechat-miniprogram/api-typings

[Bug]selectAll和select两个选择器的返回值应该是不一样的

Open
#210 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
803
Forks
117
Avg merge
24m
Merged PRs (30d)
1

Description

环境

  • 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib.wx.api.d.ts at the select and selectAll declarations and inspect the NodesRef type, especially boundingClientRect callback definitions. Update the declarations so select uses a single BoundingClientRectCallbackResult while selectAll uses an array, then verify the generated TypeScript types distinguish both callbacks.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.