Skip to content

Key datastore property bleeds into typescript Type  #173

Description

@jacobg

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions