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

运行nest build时报TS2720错误:FirebaseFirestoreService实现Firestore异常

解决方案

下面是三种经过验证的可行解决办法,可根据项目实际情况选择:

  • 方案1:固定@google-cloud/firestore兼容版本
    该问题是由于@aginix/nestjs-firebase-admin@2.1.0没有适配更高版本@google-cloud/firestore新增的recursiveDelete类型定义导致,安装兼容的旧版本即可解决:
    # npm 用户执行
    npm install @google-cloud/firestore@4.15.1 --save-dev
    # yarn 用户执行
    yarn add @google-cloud/firestore@4.15.1 -D
    
  • 方案2:跳过第三方库类型检查
    直接在项目的tsconfig.json的compilerOptions配置项中添加skipLibCheck: true,即可跳过所有node_modules下声明文件的类型校验,不会影响项目自身代码的类型检查,是成本最低的快速修复方案:
    {
      "compilerOptions": {
        // 保留原有其他配置
        "skipLibCheck": true
      }
    }
    
  • 方案3:手动补充缺失类型
    如果需要使用高版本@google-cloud/firestore,可以在项目中新增类型声明补全缺失的方法定义:
    1. 在项目根目录新建typings.d.ts文件,添加如下内容:
    declare module '@aginix/nestjs-firebase-admin' {
      import { Firestore } from '@google-cloud/firestore';
      export class FirebaseFirestoreService implements Firestore {
        recursiveDelete: Firestore['recursiveDelete'];
        // 后续如果再有缺失的方法,也可以按照该格式补充
      }
    }
    
    1. 在tsconfig.json的include数组中添加该声明文件:
    {
      "include": ["src/**/*", "typings.d.ts"]
    }
    

内容的提问来源于stack exchange,提问作者Ehsan Hesam

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.22 03:36:07