Skip to content

Custom Schema Types #163

@kjkurtz

Description

@kjkurtz

In order to handle Dates where we don't care about the time, we have a custom schema type of DateOnly that is effectively a wrapper around Date with some validators attached to make sure the time is set to midnight UTC via a plugin.

We use a types.d.ts file to make Typescript aware of this additional type which so far has worked. Now, when using mongoose-tsgen, we get an error parser: Unknown type detected for field for any fields using this new custom type.

The type looks like the following:

declare module "mongoose" {
  namespace Schema {
    namespace Types {
      class DateOnly extends Schema.Types.Date {}
    }
  }
}

So quite similar to how you are already augmenting for populate. Any ideas on how to effectively do this so types generate correctly for the schemas that use this custom type? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions