api-typings
api-typings copied to clipboard
ctx.drawImage 方法与新版 canvas api 不一致
Canvas 实例通过 SelectorQuery 获取, ctx.drawImage方法的 imageResource 实际不支持字符串类型。
Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'
定义里提供的 drawImage 接口和获取路径还是旧版的,通过 wx.createCanvasContext 获取的;新版的通过 getContext 获取的暂时还没有支持,现在应该返回的是 any。实际使用的时候有遇到问题吗?
是的,目前返回的any。 目前在使用时需要手动指定类型
let canvas = this.getCanvas() as HTMLCanvasElement & WechatMiniprogram.Canvas;
const ctx = canvas.getContext('2d')!;
const img = canvas.createImage() as CanvasImageSource;
ctx.drawImage(img, 0, 0, 100, 100);
目前官方文档已经不推荐使用 wx.createCanvasContext 接口,建议 getContext 相关的类型能够完善一下。
正在补了,wechat-miniprogram/minigame-api-typings#3 里也有跟踪
小程序已经原生支持ts了,canvas类型有很多问题,请问有什么进展吗。