Skip to content

Export pre-Mongoose v9 behavior of InferRawDocType #15814

@JavaScriptBach

Description

@JavaScriptBach

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Before 91d803d#diff-99f950366dead983bb820aa9c5ef5f35bb63f00acb4185c649fb54b91afc67fdL14, InferRawDocType used to return the inferred type of the schema definition, e.g.

const foo = { field1: {type: String; required: true}};
type Foo = InferRawDocType<typeof foo> // {field1: string}

In Mongoose 9, Foo is now typed as {field1: string, _id: ObjectId}.

Can we export a type alias that replicates the legacy behavior? Open to whatever you want on the name; I'd suggest something like InferPojoType. Happy to make a PR too.

Motivation

I have a large Typescript mono-repo with hundreds of typed Mongoose schemas. Large parts of our type-checking depend on the behavior of InferRawDocType. I need the legacy behavior in order to migrate to Mongoose 9.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featurenew featureThis change adds new functionality, like a new method or class

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions