Allow type hints when inferring schema type #14002
Labels
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
new feature
This change adds new functionality, like a new method or class
Prerequisites
馃殌 Feature Proposal
Allow the user to specify type hints for individual schema fields, which are then respected by
InferSchemaType
.Motivation
This makes Mongoose more useful in strongly typed codebases. For example, the codebase I work in has separate types for
UserId
andTeamId
, even though both are strings at runtime. We use branded types to ensure that e.g. if a developer passes in a team ID when they should pass in a user ID, their error will be discovered at type-checking time instead of at runtime.Example
Due to the way
InferSchemaType
is implemented, I can't think of a way to keep this type-only, but would you consider something like:Happy to write a PR for this, if you're okay with the approach. Thanks!
The text was updated successfully, but these errors were encountered: