当前位置: 首页 > 工具软件 > fastclick > 使用案例 >

FastClick报错Property ‘attach‘ does not exist on type ‘typeof fastclick‘

潘佐
2023-12-01

问题描述

FastClick报错Property 'attach' does not exist on type 'typeof fastclick'

用法如下:
安装fastclick和@types/fastclick
main.ts

import fastclick from 'fastclick'
fastclick.attach(document.body)

然后先是去搜索了一下,然后得到清一色的结论——修改node_modules
node_modules@types\fastclick\index.d.ts

declare module "fastclick" {
    // function fastclick(layer: any, options?: FastClickOptions): FastClickObject;
    // namespace fastclick {
    //     var FastClick: FastClickStatic;
    // }
    var fastclick: FastClickStatic;
    export = fastclick;
}

这样做会有比较大的弊端,明显非常不合理!
首先,每次重新安装node_modules都要修改;其次,如果发布到生产环境,那么就需要修改生产环境的node_modules;由于在用阿里云流水线,并没有提供修改文件的入口。


解决方案

import fastclick from 'fastclick'
fastclick.FastClick.attach(document.body)
 类似资料: