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

CanvasContext 类的方法 measureText 的定义出错 #2988

Closed
ZackZheng2014 opened this issue May 8, 2019 · 4 comments
Closed

CanvasContext 类的方法 measureText 的定义出错 #2988

ZackZheng2014 opened this issue May 8, 2019 · 4 comments

Comments

@ZackZheng2014
Copy link

问题描述
在 class CanvasContext 的定义中,measureText 方法的参数和返回值定义有误。根据注释和举例,第一个方法参数本意是text,类型为string,返回值为 TextMetrics 对象,结构包含 width,但是方法却定义成 measureText(width: number): void。

复现步骤

  1. 添加依赖 "@tarojs/taro": "1.2.15"

  2. 查看库文件 taro/types/index.d.ts

    /**
     * > 基础库 1.9.90 开始支持,低版本需做[兼容处理](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
     *
     * **定义:**
     *
     * 测量文本尺寸信息,目前仅返回文本宽度。同步接口。
     *
     * **参数:**
     *
     *   参数   |  类型     |  说明
     * ---------|-----------|-----------
     *   text   |  String   |要测量的文本
     *
     * **返回:**
     *
     * 返回 TextMetrics 对象,结构如下:
     *
     *   参数    |  类型     |  说明
     * ----------|-----------|----------
     *   width   |  Number   |文本的宽度
     *
     * **例子:**
     *
     *     ```javascript
     *     const ctx = Taro.createCanvasContext('myCanvas')
     *     ctx.font = 'italic bold 20px cursive'
     *     const metrics = ctx.measureText('Hello World')
     *     console.log(metrics.width)
     *     ```
     */
    measureText(width: number): void

期望行为
期望修正 CanvasContext 类的方法 measureText 的定义。

报错信息

类型“"测试文本"”的参数不能赋给类型“number”的参数。ts(2345)

系统信息

👽 Taro v1.2.26

Taro CLI 1.2.26 environment info:
System:
OS: macOS 10.14.5
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.5.0 - /usr/local/bin/node
Yarn: 1.15.2 - ~/.yarn/bin/yarn
npm: 6.1.0 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: 1.2.15 => 1.2.15
@tarojs/cli: 1.2.15 => 1.2.15
@tarojs/components: 1.2.15 => 1.2.15
@tarojs/plugin-babel: 1.2.15 => 1.2.15
@tarojs/plugin-csso: 1.2.15 => 1.2.15
@tarojs/plugin-less: 1.2.15 => 1.2.15
@tarojs/plugin-sass: 1.2.15 => 1.2.15
@tarojs/plugin-uglifyjs: 1.2.15 => 1.2.15
@tarojs/redux: 1.2.15 => 1.2.15
@tarojs/redux-h5: 1.2.15 => 1.2.15
@tarojs/router: 1.2.15 => 1.2.15
@tarojs/taro: 1.2.15 => 1.2.15
@tarojs/taro-alipay: 1.2.15 => 1.2.15
@tarojs/taro-h5: 1.2.15 => 1.2.15
@tarojs/taro-swan: 1.2.15 => 1.2.15
@tarojs/taro-tt: 1.2.15 => 1.2.15
@tarojs/taro-weapp: 1.2.15 => 1.2.15
@tarojs/webpack-runner: 1.2.15 => 1.2.15
eslint-config-taro: 1.2.15 => 1.2.15
eslint-plugin-taro: 1.2.15 => 1.2.15
nervjs: ^1.3.9 => 1.3.9

@taro-bot
Copy link

taro-bot bot commented May 8, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@luckyadam
Copy link
Member

你可以提个 pr 咯

@ZackZheng2014
Copy link
Author

@luckyadam 刚看到 1.3.0 beta 已经修了,那就不用提了哈~

@Garfield550
Copy link
Collaborator

你说的问题已经在 PR #2768 修了,今天看到这个 issue 吓死我了,一看你一直在用 1.2.15,常更新啊朋友,会省很多时间填坑的

@yuche yuche closed this as completed May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants