Following the documentation on using gstore-node with Typescript, I had to define a custom Type which has a key property in the following way:
type ChildType = {
// It's not great that the type needs to bleed datastore semantics.
// The type is supposed to be datastore-agnostic.
// Probably a string id value is more appropriate.
parentField: entity.Key
}
const ChildSchema = new gstore.Schema<ChildType>({
parentField: { type: gstore.Schema.Types.Key, ref: ParentModel.entityKind }
})
const ChildModel = gstore.model<ChildType>('ChildType', ChildSchema)
I had tried using a string or a long type on the parentField, but it causes a compile error when calling new ChildModel({ ... }).
It would seem that the ChildType's parentField should be database-agnostic, and maybe an int | string union type. Can't the kind and namespace be inferred from the child entity itself?
Following the documentation on using gstore-node with Typescript, I had to define a custom Type which has a key property in the following way:
I had tried using a
stringor alongtype on theparentField, but it causes a compile error when callingnew ChildModel({ ... }).It would seem that the
ChildType'sparentFieldshould be database-agnostic, and maybe anint | stringunion type. Can't thekindandnamespacebe inferred from the child entity itself?