Skip to content

Commit 1cc8ccb

Browse files
committed
feat: update baselib defs to 2.24.6
1 parent aa73e6b commit 1cc8ccb

File tree

6 files changed

+1125
-169
lines changed

6 files changed

+1125
-169
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
## 2022-06-24 v3.5.0
2+
- 更新 API 定义到 2.24.6
3+
14
## 2022-04-01 v3.4.6
25
- 更新 API 定义到 2.23.2
6+
37
## 2022-01-20 v3.4.5
48
- 更新 API 定义到 2.21.3
59

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniprogram-api-typings",
3-
"version": "3.4.6",
3+
"version": "3.5.0",
44
"description": "Type definitions for APIs of Wechat Mini Program in TypeScript",
55
"main": "./index.d.ts",
66
"types": "./index.d.ts",

test/api-doc.test.ts

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,6 +4142,49 @@ type TPlatform = 'ios' | 'android' | 'windows' | 'mac'
41424142
})
41434143
}
41444144

4145+
// Test case from `wx.createVKSession`
4146+
{
4147+
const gl: WechatMiniprogram.WebGLRenderingContext = {}
4148+
const canvasWidth = 300
4149+
const canvasHeight = 300
4150+
// 以下 demo 以 v2 为例
4151+
// 创建 session 对象
4152+
const session = wx.createVKSession({
4153+
track: {
4154+
plane: {mode: 3},
4155+
},
4156+
version: 'v2',
4157+
gl,
4158+
})
4159+
// 逐帧分析
4160+
const onFrame = (timestamp: number) => {
4161+
// 开发者可以自己控制帧率
4162+
const frame = session.getVKFrame(canvasWidth, canvasHeight)
4163+
if (frame) {
4164+
// 分析完毕,可以拿到帧对象
4165+
doRender(frame)
4166+
}
4167+
4168+
expectType<number>(timestamp)
4169+
4170+
session.requestAnimationFrame(onFrame)
4171+
}
4172+
session.start(err => {
4173+
if (!err) session.requestAnimationFrame(onFrame)
4174+
})
4175+
4176+
// 渲染函数
4177+
const doRender = (frame: WechatMiniprogram.VKFrame) => {
4178+
expectType<WechatMiniprogram.VKFrame>(frame)
4179+
}
4180+
}
4181+
4182+
// Test case from `wx.isVKSupport`
4183+
{
4184+
const isSupportV2 = wx.isVKSupport('v2')
4185+
expectType<boolean>(isSupportV2)
4186+
}
4187+
41454188
// Test case from `FileSystemManager.readCompressedFile`
41464189
{
41474190
const fs = wx.getFileSystemManager()
@@ -4503,3 +4546,139 @@ type TPlatform = 'ios' | 'android' | 'windows' | 'mac'
45034546
disableNormalization: true,
45044547
})
45054548
}
4549+
4550+
// Test case from `wx.preloadAssets`
4551+
{
4552+
let imgUrl = ''
4553+
wx.preloadAssets({
4554+
data: [
4555+
{
4556+
type: 'image',
4557+
src: imgUrl,
4558+
},
4559+
],
4560+
success(resp) {
4561+
console.log('preloadAssets success', resp)
4562+
},
4563+
fail(err) {
4564+
console.log('preloadAssets fail', err)
4565+
},
4566+
})
4567+
}
4568+
4569+
// Test case from `wx.editImage`
4570+
{
4571+
wx.editImage({
4572+
src: '', // 图片路径
4573+
})
4574+
}
4575+
4576+
// Test case from `wx.createCacheManager`
4577+
{
4578+
const cacheManager = wx.createCacheManager({})
4579+
cacheManager.addRule(/https:\/\/(?:.*)/ig) // 表示所有 https 请求都匹配
4580+
4581+
cacheManager.on('request', evt => {
4582+
// 在弱网时接收到 wx.request 请求
4583+
return new Promise((resolve, reject) => {
4584+
const matchRes = cacheManager.match(evt)
4585+
if (matchRes && matchRes.data) {
4586+
// 有缓存,返回
4587+
resolve(matchRes.data)
4588+
} else {
4589+
// 没缓存,抛错
4590+
reject({ errMsg: 'no cache' })
4591+
}
4592+
})
4593+
})
4594+
}
4595+
4596+
// Test case from `CacheManager.addRule`
4597+
{
4598+
const cacheManager = wx.createCacheManager({})
4599+
const ruleId = cacheManager.addRule({
4600+
id: 'haha-rule',
4601+
method: 'GET',
4602+
url: '/haha',
4603+
maxAge: 123455,
4604+
dataSchema: [
4605+
// data 字段的匹配,默认为空,表示不匹配
4606+
// 类型可以是:string、number、boolean、null、object、any(表示任意类型均可),以及这些类型的数组表示方式
4607+
{name: 'aaa', schema: {type: 'string'}}, // 类型为 string
4608+
{name: 'bbb', schema: [{type: 'number'}, {type: 'string'}]}, // 类型为 number, string
4609+
{name: 'ccc', schema: {type: 'string', value: 'abc'}}, // 值为 abc
4610+
{name: 'ddd', schema: {type: 'string', value: /(abc|cba)/ig}}, // 值符合该正则匹配,如果该值不是字符串类型,则会被尝试转成字符串后再进行比较
4611+
{name: 'ddd', schema: {type: 'string', value: (val: string) => val === '123'}}, // 传入函数来校验值
4612+
{name: 'eee', schema: {type: 'object', value: [{ // 类型为对象,则通过嵌套的方式来逐层校验
4613+
name: 'aaa', schema: {type: 'string'},
4614+
// ...
4615+
// 嵌套 dataSchema,同上面的方式一样来匹配嵌套的对象
4616+
}]}},
4617+
{name: 'fff', schema: {type: 'string[]'}}, // 类型为 string 数组
4618+
{name: 'ggg', schema: {type: 'any'}}, // 类型为任意类型
4619+
{name: 'hhh', schema: {type: 'any[]'}}, // 类型为任意类型的数组
4620+
],
4621+
})
4622+
expectType<string>(ruleId)
4623+
}
4624+
4625+
// Test case from `CacheManager.on`
4626+
{
4627+
const cacheManager = wx.createCacheManager({})
4628+
cacheManager.on('request', async function () {
4629+
// evt.url - 请求 url
4630+
// evt.data - 请求参数
4631+
// evt.method - 请求方法
4632+
// evt.request - 原始 request 方法,返回一个 promise
4633+
4634+
// if (evt.url === '/xxx') {
4635+
// // 如果有些请求仍然希望走到网络,则可以如下处理
4636+
// const res = await evt.request()
4637+
// // res 即为网络请求返回
4638+
// }
4639+
4640+
return new Promise((resolve, reject) => {
4641+
// do sth
4642+
let data = {}
4643+
if (data) {
4644+
// 这里 resolve 的 data 就会作为 wx.request 的 success 回调结果返回
4645+
resolve(data)
4646+
} else {
4647+
// 这里 reject 的错误信息就会作为 wx.request 的 fail 回调结果返回
4648+
reject('no data')
4649+
}
4650+
})
4651+
})
4652+
}
4653+
4654+
// Test case from `CacheManager.match`
4655+
{
4656+
const cacheManager = wx.createCacheManager({})
4657+
cacheManager.on('request', (evt) => {
4658+
const cache = cacheManager.match(evt)
4659+
// 若有重复监听,则取第一个 handler 返回的 promise
4660+
return new Promise((resolve, reject) => {
4661+
if (cache.data) {
4662+
resolve(cache.data)
4663+
} else {
4664+
reject('no cache')
4665+
}
4666+
})
4667+
})
4668+
}
4669+
4670+
// Test case from `wx.requestPluginPayment`
4671+
{
4672+
wx.requestPluginPayment({
4673+
version: 'release',
4674+
fee: 1,
4675+
paymentArgs: {},
4676+
currencyType: 'CNY',
4677+
success (res) {
4678+
expectType<string>(res.errMsg)
4679+
},
4680+
fail (res) {
4681+
expectType<string>(res.errMsg)
4682+
}
4683+
})
4684+
}

0 commit comments

Comments
 (0)