There are different scenarios in which interfaces can be implemented:
interface MyInterface {
// viewCount: { [userId: string]: number };
downloaded?: { [userId: string]: boolean };
}
export type MyInterfaceUpdate = admin.firestore.UpdateData<MyInterface>;
export function a() {
let a = "asdf"
const update: MyInterfaceUpdate = {
[`downloaded.${a}`]: true,
// ['viewCount.testUser']: 23,
}
}
Keep in mind that there should only be one map in the interface.
Alternatively, another implementation could look like this:
interface MyInterface {
viewCount: { [userId: string]: number };
downloaded?: { [userId: string]: boolean };
}
export type MyInterfaceUpdate = admin.firestore.UpdateData<MyInterface>;
export function a() {
const update: MyInterfaceUpdate = {
[`downloaded.asdf`]: true,
['viewCount.testUser']: 23,
}
}
It seems that combining both implementations may lead to an error. Why is that so?
Take a look at the combined approach:
interface MyInterface {
viewCount: { [userId: string]: number };
downloaded?: { [userId: string]: boolean };
}
export type MyInterfaceUpdate = admin.firestore.UpdateData<MyInterface>;
export function a() {
let a = "asdf"
const update: MyInterfaceUpdate = { // Error here "index sigbatures are incompatible"
[`downloaded.${a}`]: true,
['viewCount.testUser']: 23,
}
}
Remember, it will work if downloaded
and viewCount
have the same types (both string or boolean).
Is there a way to make these combinations work harmoniously? :)