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

Arguments' types of the transform function should be improved. #13421

Closed
2 tasks done
mrdulin opened this issue May 20, 2023 · 1 comment · Fixed by #13446
Closed
2 tasks done

Arguments' types of the transform function should be improved. #13421

mrdulin opened this issue May 20, 2023 · 1 comment · Fixed by #13446
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@mrdulin
Copy link

mrdulin commented May 20, 2023

Prerequisites

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

Issue

"mongoose": "^7.1.1"

Currently, these arguments' types are all any, see:

mongoose/types/index.d.ts:

  export interface ToObjectOptions {  
    /** if set, mongoose will call this function to allow you to transform the returned object */
    transform?: boolean | ((doc: any, ret: any, options: any) => any);
  }

I use HydratedDocument<Something> to specify the type for the doc argument, but I am not sure it's correct.

import mongoose, { HydratedDocument } from 'mongoose';

interface Something {
  name: string;
}
const somethingSchema = new mongoose.Schema<Something>({
  name: String
}, {
  collection: 'something',
  toJSON: {
    transform(doc: HydratedDocument<Something>) {

    },
  }
}

Any suggestion?

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label May 22, 2023
@vkarpov15
Copy link
Collaborator

HydratedDocument<Something> is correct in that case. We'll update the types.

@vkarpov15 vkarpov15 added this to the 7.2.2 milestone May 23, 2023
vkarpov15 added a commit that referenced this issue May 27, 2023
types: improve function parameter types for `ToObjectOptions` transform option
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