miniprogram-api-promise
miniprogram-api-promise copied to clipboard
能支持typescript 吗
自定义
// definition.d.ts 放在 src 根目录即可
declare module 'miniprogram-api-promise' {
type ParamType<T> = T extends (option: infer P) => any ? P : T
type SuccessCallback<T> = NonNullable<NonNullable<ParamType<T>>['success']>
type ResultType<T> = ParamType<SuccessCallback<T>>
type Wx = WechatMiniprogram.Wx
type WxAsyncFunctionKeys = {
[K in keyof Wx]: NonNullable<ParamType<Wx[K]>> extends { success?: any } ? K : never
}[keyof Wx]
type Wxp = {
[P in WxAsyncFunctionKeys]: (option: ParamType<Wx[P]> = {}) => Promise<ResultType<Wx[P]>>
}
export declare function promisify<Func>(func: Func): (option: ParamType<Func> = {}) => Promise<ResultType<Func>>
export declare function promisifyAll(wx: Wx, wxp: Wxp): void
}
@listenzz 你的代码直接用不了,很多报错。
@MoonBall 我这边没问题哦
我们用的版本:
"typescript": "^3.5.3",
"miniprogram-api-typings": "^2.9.3",
我们 tsconfig.json
{
"compilerOptions": {
"skipLibCheck": true,
"resolveJsonModule": true,
"target": "es5",
"lib": ["ES2016"],
"module": "es6",
"strict": true,
"moduleResolution": "node",
"typeRoots": ["./node_modules/@types", "./node_modules/miniprogram-api-typings"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"downlevelIteration": true
},
"exclude": ["node_modules", "dist", "webpack.config.js", "jest.config.js"]
}
@listenzz 请问引用之后该如何定义新的wx对象?
@helloforrestworld
const wxp = {} as Wxp
@listenzz 感谢回复 我导出了Wxp可以了