kossnocorp / typesaurus

🦕 Type-safe TypeScript-first ODM for Firestore
https://typesaurus.com
415 stars 36 forks source link

Computed property names #94

Closed ghayman closed 3 years ago

ghayman commented 3 years ago

Having trouble getting Typosaurus accepting this update

`
await admin.firestore().collection('users').doc(context.auth!.uid).set({

devices: {
  [`${token}`]: {
    osType: osType,
    updatedAt: dateFormat(new Date(), 'isoDateTime'),
  },
},

}, {merge: true}); `

Fields() doesn;t seem to want to take the derived property name - [${token}]

Any pointers?

Sorry if this not the right place to ask - I couldn't see any other discussion places.

Thanks!e

ghayman commented 3 years ago

Turns out that the issue is not with computed property names but the fact that 'devices' above was defined as optional in the Interface. Also, updated the type definition for Map fields

e.g. interface Devices { optionalField?: {

} requiredField: {

}

await db.update(users, uid, [ db.field(['optionalField', token], { osType, modifiedAt: new Date(), }), ]);

fails with "Type 'string' is not assignable to type 'never'."

await db.update(users, uid, [ db.field(['requireField', token], { osType, modifiedAt: new Date(), }), ]);

works fine. Not sure if this is the expected behavior or not but this is how I worked around it.