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

SchemaTypeOptions is inaccessible with a pre-defined interface (typescript) #9911

Closed
ShadiestGoat opened this issue Feb 9, 2021 · 0 comments
Assignees
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@ShadiestGoat
Copy link
Contributor

ShadiestGoat commented Feb 9, 2021

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

bug

What is the current behavior?

You are unable to reach the SchemaTypeOptions if using a pre-made interface.

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

export interface IUser { 
    username: string,
    password: string,
}
type SH = IUser & Document

const SH = new Schema<SH, Model<SH>, SH>({
    username: {unique: true, type: String},
    password: String,
})

username: {unique: true, type: String}
Gives of an error since its not String (not SchemaDefinitionProperty<string>)

Also, if I would try to do something like export type SH = Omit<IUser, "username"> & Document & {username: SchemaTypeOptions<String>}, then i would get an error that

Type '{ unique: true; type: StringConstructor; }' is not assignable to type 'SchemaDefinitionProperty<SchemaTypeOptions<String>>'. Type '{ unique: true; type: StringConstructor; }' is not assignable to type 'string'

tsconfig.json is irrelevant

What is the expected behavior?

That you are able to get to SchemaTypeOptions, somehow.

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

5.11.15

Edit:
Technically, you can access it, through the use of

type SH = Omit<IUser, "username"> & Document & {username: any}

But that feels like a very work around-ish way to do it. Is there a better way for this? Because i see that the type definition for the SchemaTypeOptions having a generics type there, so I assume there was intended to be a way for it?

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Feb 11, 2021
@vkarpov15 vkarpov15 added this to the 5.11.17 milestone Feb 15, 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