对于在Firestore文档的TypeScript界面中如何定义数组值,我还有些困惑,同时还利用了FieldValue.arrayUnion()。依赖关系:TypeScript 3.7.2和@ google-cloud / firestore 2.6.0。
即。该界面包括一个“成员”键,该键是一个字符串数组:
import * as firestore from "@google-cloud/firestore";
interface SomeDoc {
members: string[] | firestore.FieldValue;
}
const foo: SomeDoc = {
members: ["s"]
};
const bar = foo.members.includes("s") ? "does include" : "does not include";
我可以使用Firestore的FieldValue arrayUnion()和arrayRemove()方法成功更新值,这很棒。但是,TypeScript会引发以下类型错误:
TypeScript error:
Property 'includes' does not exist on type 'string[] | FieldValue'.
Property 'includes' does not exist on type 'FieldValue'. TS2339
有人对如何最好地定义这种价值有任何提示吗?