能支持typescript 吗
Opened this issue · 6 comments
yytm commented
能支持typescript 吗
listenzz commented
自定义
// 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 commented
@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"]
}helloforrestworld commented
@listenzz 请问引用之后该如何定义新的wx对象?

listenzz commented
const wxp = {} as Wxphelloforrestworld commented
@listenzz 感谢回复 我导出了Wxp可以了


