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

Support string initialization for map in schema #13755

Closed
2 tasks done
dayo05 opened this issue Aug 21, 2023 · 4 comments · Fixed by #13960
Closed
2 tasks done

Support string initialization for map in schema #13755

dayo05 opened this issue Aug 21, 2023 · 4 comments · Fixed by #13960
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@dayo05
Copy link

dayo05 commented Aug 21, 2023

Prerequisites

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

🚀 Feature Proposal

My project uses String for setting the type in schema of each keys like this:

username: { type: 'string', required: true }

In case of map, I just tried this style of code:

instance: {
  type: Schema.Types.Map,
  of: Schema.Types.Mixed,
  default: new Map<string, any>(),
}

This is working code. But if I use 'Map' instead of Schema.Types.Map, compiler aborts to compile.

instance: {
  type: 'Map',
  of: 'Mixed',
  default: new Map<string, any>(),
}

So, is it able to allow with setting the map type with String?

Motivation

No response

Example

No response

@dayo05 dayo05 added 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 labels Aug 21, 2023
@vkarpov15 vkarpov15 added this to the 7.4.5 milestone Aug 21, 2023
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed new feature This change adds new functionality, like a new method or class enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature labels Aug 21, 2023
@vkarpov15 vkarpov15 modified the milestones: 7.4.5, 7.5.1, 7.5.2 Aug 25, 2023
@IslandRhythms IslandRhythms added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Aug 29, 2023
@IslandRhythms
Copy link
Collaborator

import * as mongoose from 'mongoose';

const testSchema = new mongoose.Schema({
  instance: {
    type: 'Map',
    of: 'Mixed',
    default: new Map<string, any>()
  }
})

@vkarpov15 vkarpov15 removed this from the 7.5.2 milestone Sep 4, 2023
@github-actions
Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Sep 19, 2023
@dayo05
Copy link
Author

dayo05 commented Sep 19, 2023

Sorry for late reply, I was so busy for some reasons...

It looks like my issue seems like typescript problem.

TS2322: Type
{     type: string;     of: typeof Schema.Types.ObjectId;     default: Map<string, ObjectId>; }
is not assignable to type
Map<string, ObjectId> | SchemaDefinitionProperty<Map<string, ObjectId>>

This is actual error message what I saw.
Because its just type error, it might be able to worked on javascript(not typescript).

I'll just make minimal project ASAP.

Thanks for focusing on this

@dayo05
Copy link
Author

dayo05 commented Sep 19, 2023

class Test {
  instance: Map<string, string>
  constructor() {
    this.instance = new Map<string, string>()
  }
}

const testSchema = new mongoose.Schema<Test>({
  instance: {
    type: 'Map',
    of: 'Mixed',
    default: new Map<string, string>()
  }
})

This is minimal reproduction script

@github-actions github-actions bot removed the Stale label Sep 20, 2023
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Sep 26, 2023
@vkarpov15 vkarpov15 added this to the 7.5.5 milestone Sep 26, 2023
vkarpov15 added a commit that referenced this issue Oct 9, 2023
@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Oct 9, 2023
vkarpov15 added a commit that referenced this issue Oct 10, 2023
types(schematypes): allow defining map path using `type: 'Map'` in addition to `type: Map`
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
3 participants