Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
iamjackchen opened this issue Jul 15, 2024 · 1 comment · Fixed by #14756
Closed
2 tasks done

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

iamjackchen opened this issue Jul 15, 2024 · 1 comment · Fixed by #14756
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@iamjackchen
Copy link

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

@Imanghvs
Copy link

They are required fields according to the the docs here: https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.cast()
I'm not sure how it works without typescript. Maybe the code handles undefined values somehow.

@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Jul 21, 2024
@vkarpov15 vkarpov15 added this to the 8.5.2 milestone Jul 21, 2024
vkarpov15 added a commit that referenced this issue Jul 26, 2024
types: allow calling `SchemaType.cast()` without `parent` and `init` parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants