typescript
中引用better-scroll
,代码如下
import * as BScroll from 'better-scroll'
...
console.log(BScroll)
new BScroll('.wrapper')
...
控制台输出
{default: ƒ, __esModule: true}
> default:ƒ BScroll(el, options)
__esModule:true
> __proto__:Object
> Uncaught TypeError: BScroll is not a constructor
...
检查作者package.json
中types
声明没问题
...
"types": "./types/index.d.ts",
...
检查作者*.d.ts
没问题
...
declare const BScroll: BScrollStatic;
declare module 'better-scroll' {
export = BScroll;
}
...
求助,我这里是哪里错误了?
问题在于这句话
new BScroll('.wrapper')
,错误很明显了,BScroll 不是一个构造器函数, 所以你不能使用new运算符。
你应该可以直接这么用吧
BScroll('.wrapper')
.