升级Firebase 9后导入Firestore的FieldValue报错该如何解决
Firebase 9 非兼容模式 Firestore 类型导入方案
报错原因
Firebase 9 重构为模块化API,废弃了旧版本的全局firebase命名空间设计,非compat模式下不再支持firebase.firestore.xxx的层级访问写法,因此会触发找不到firestore导出成员的报错。
正确实现方式
直接从firebase/firestore包中导入需要的具体类型即可,无需依赖兼容层,你测试验证过的写法就是官方推荐的标准写法:
import { Timestamp, FieldValue } from "firebase/firestore"; export interface ModelTest { date?: FieldValue | Timestamp | Date; }
扩展说明
其他所有Firestore相关的类型、工具方法都可以用相同的直接导入方式使用,比如常用的DocumentReference、QuerySnapshot、WriteBatch等,都不需要再通过旧的命名空间层级调用。
内容的提问来源于stack exchange,提问作者user8836786
相关产品推荐
相关产品推荐

