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

Incompatible types with array of ObjectId after upgrading to 6.0.1 #10623

Closed
pqvst opened this issue Aug 26, 2021 · 1 comment
Closed

Incompatible types with array of ObjectId after upgrading to 6.0.1 #10623

pqvst opened this issue Aug 26, 2021 · 1 comment
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@pqvst
Copy link

pqvst commented Aug 26, 2021

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Creating a schema with an array of ObjectId and defining a corresponding TypeScript interface causes a compiler error, stating that the types are incompatible.

A single ObjectId (no array) works fine though. Arrays of other types also work fine. It just seems to be array of ObjectId which is problematic.

image

If the current behavior is a bug, please provide the steps to reproduce.

import { Schema, model, ObjectId, Document } from 'mongoose';

interface Foo extends Document<ObjectId> {
  arrayOfObjectId: ObjectId[];
}

const fooSchema = new Schema<Foo>({
  arrayOfObjectId: { type: [Schema.Types.ObjectId], required: true },
});

tsconfig.json

{
  "compilerOptions": {
    "outDir": "./build",
    "allowJs": true,
    "target": "ES2018",
    "module": "CommonJS",
    "sourceMap": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "typeRoots": [
      "types", // must be first!
      "node_modules/@types"
    ]
  }
}

What is the expected behavior?
Before upgrading to mongoose v6 I was able to create a schema with an array of ObjectId and use a corresponding TypeScript interface.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: v16.3.0
mongoose: 6.0.1

@vkarpov15 vkarpov15 added this to the 6.0.3 milestone Aug 26, 2021
@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Aug 27, 2021
@vkarpov15 vkarpov15 modified the milestones: 6.0.3, 6.0.4 Aug 30, 2021
@vkarpov15
Copy link
Collaborator

This appears to be fixed by the fix for #10605

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

No branches or pull requests

3 participants