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

本文讲述了在使用FastClick时遇到的错误'Property 'attach' does not exist on type 'typeof FastClick'。作者提供了不建议的修改node_modules解决方法,并给出了更合理的解决方案,包括直接导入FastClick并调用FastClick.attach()。适合前端开发者遇到类似问题时参考。
摘要由CSDN通过智能技术生成

问题描述

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)
  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值