Skip to content

Optional Arguments in SchemaTypes.path().cast required by Typescript #14748

@iamjackchen

Description

@iamjackchen

Prerequisites

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

Mongoose version

7.6.7

Node.js version

18.20.3

MongoDB server version

7.0.12

Typescript version (if applicable)

5.2.2

Description

It looks like the typescript signature for SchemaTypes.path().cast require some (what appear to be) optional fields.

I wanted to create a subdocument instance without creating a model. With reference to #9076,

I had
image

which works exactly as intended with the //@ts-ignore, but otherwise gives me a type error. Upon further examination,
it appears that
image
doc and init are required fields in the typescript signature, whereas they seem to be optional in a lot of the documentation I've seen.

This is my top-level schema file:
image

Please let me know if I'm mistaken somewhere, many thanks!!

Steps to Reproduce

Please see above.

Expected Behavior

Optional (?) fields should be required by typescript signature

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypes or Types-test related issue / Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions