You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用@googlemaps/markerclusterer遇TS2339错误求解决方案

解决@googlemaps/markerclusterer的TypeScript错误:Property 'radius' does not exist on type 'SuperClusterViewportOptions'

问题根源

@googlemaps/markerclusterer v2.5.1的类型定义存在错误:SuperClusterViewportOptions接口未声明radius属性,但构造函数代码却尝试解构该属性,导致TypeScript编译报错。

可行解决办法

  • 升级库版本(推荐)
    该问题在v2.5.2版本已被修复,修改package.json中@googlemaps/markerclusterer的版本为^2.5.2或更高,然后执行依赖安装命令:

    npm install
    # 或
    yarn install
    
  • 临时类型补丁(无法升级时使用)
    在项目中创建类型声明文件补充缺失属性,比如src/types/google-maps-markerclusterer.d.ts,内容如下:

    declare module '@googlemaps/markerclusterer/dist/algorithms/superviewport' {
      interface SuperClusterViewportOptions {
        radius?: number;
      }
    }
    

    确保tsconfig.json的include数组包含该类型文件路径:

    "include": [
      "src/**/*",
      "src/types/**/*.d.ts"
    ]
    
  • 移除冲突依赖
    注意到index.html中引入了markerclustererplus的CDN资源,这与@googlemaps/markerclusterer属于同类库,可能引发冲突,建议移除该CDN引用。

相关问题说明

对应的GitHub社区问题显示,该错误是v2.5.1版本引入的回归问题,开发团队在v2.5.2版本中已通过给SuperClusterViewportOptions接口添加radius可选属性完成修复。

内容的提问来源于stack exchange,提问作者Raphaël Balet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 04:02:22