之前TypeSrcipt 模板里面 package.json 中dependencies 里面没有 miniprogram-api-typings。
npm install miniprogram-api-typings
之后在 tsconfig.json 中修改
typeRoots : [
"./node_modules/miniprogram-api-typings"
]
1.编译出现 错误
miniprogram/pages/auc/special/special.ts:62:3 - error TS2345: Argument of type '{ data: { curPage: number; pageSize: number; specials: never[]; session: {}; sesCode: string; loading: false; footer: false; showmask: false; loadAfresh: false; }; onLoad(options: any): void; onPullDownRefresh(): void; ... 4 more ...; handleTapLots(event: any): void; }' is not assignable to parameter of type 'Options<{ curPage: number; pageSize: number; specials: never[]; session: {}; sesCode: string; loading: boolean; footer: boolean; showmask: boolean; loadAfresh: boolean; }, {}>'.
Object literal may only specify known properties, and 'eventLoadAfresh' does not exist in type 'Options<{ curPage: number; pageSize: number; specials: never[]; session: {}; sesCode: string; loading: boolean; footer: boolean; showmask: boolean; loadAfresh: boolean; }, {}>'.
62 eventLoadAfresh() {
2.miniprogram-api-typings 文件里面也出现错误
node_modules/miniprogram-api-typings/types/wx/lib.wx.api.d.ts:15775:15 - error TS2451: Cannot redeclare block-scoped variable 'console'.
15775 declare const console: WechatMiniprogram.Console
~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:17510:13
17510 declare var console: Console;
~~~~~~~
'console' was also declared here.
Cannot redeclare block-scoped variable 'console' 的问题参见 https://github.com/wechat-miniprogram/api-typings/issues/66
special.ts 报错的问题,看起来是没有正确推导方法。special.ts 的代码可以看一下吗?不用具体逻辑,主要是看看函数签名和 Page 构造器的调用有没有定义没覆盖到的情况,谢谢~
2. 编译类库报错 看了你发的链接 有对比最新的 tsconfig.json 文件,1. 添加 "lib": ["es5"] 2. include 引用 miniprogram 【旧项目typings 还未删除】
我这报node_modules/miniprogram-api-typings/types/wx/lib.wx.api.d.ts:3853:19 - error TS2304: Cannot find name 'current'.