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

SchemaDefinition does not yield correct type for the type property for sub schema arrays #10537

Closed
skrtheboss opened this issue Aug 3, 2021 · 0 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@skrtheboss
Copy link
Contributor

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

Bug

What is the current behavior?

import { Model, Schema } from 'mongoose';

interface FooInterface {
    foo: string;
}

const fooSchema = new Schema<FooInterface, Model<FooInterface>, FooInterface>({ foo: { type: Schema.Types.String } });

interface BarInterface {
    bar: FooInterface[];
}

// Works
const barSchema = new Schema<BarInterface, Model<BarInterface>, BarInterface>({ bar: [fooSchema] });

// Does not work
const bar1Schema = new Schema<BarInterface, Model<BarInterface>, BarInterface>({
    bar: { type: [fooSchema], required: true },
});

What is the expected behavior?
Assigning a sub schema to type should work.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

node -v
v14.15.5
mongoose -v
v5.13.5
@skrtheboss skrtheboss changed the title SchemaDefinition does not yiel correct type for the type property for sub schema arrays SchemaDefinition does not yield correct type for the type property for sub schema arrays Aug 3, 2021
@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Aug 3, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.13.6, 5.13.7 Aug 8, 2021
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