Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.96k stars 3.84k forks source link

required does not exist on Schema typescript definition #11074

Closed lifeiscontent closed 2 years ago

lifeiscontent commented 2 years ago

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

What is the current behavior? TypeScript defintions are out of sync with reality

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

What is the expected behavior? TypeScript definitions work as intended

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

Reproduction:

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbwMoGMAWBTEBDAvnAMyghDgHIQIA7AcwggGcMyBuAKDZWofgPrgC8cKhgDucVJhwAKBGziF6ALgkwowWgBp5cKBgCOAV2B6AJirWGMbXAEogA

JavaScript code in relation to issue:

https://github.com/Automattic/mongoose/blob/d459fbe2bbfd542b510e52c2f2d0c073eb3c8714/lib/options/SchemaTypeOptions.js#L95

vkarpov15 commented 2 years ago

Works as expected. required is defined here and the example you pasted is incorrect:

import {Schema} from 'mongoose';

const foo = new Schema({
  foo: String,
  required: true // <-- tries to define a schema property of type `true`, which is incorrect
})