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

Document<T = any> in index.d.ts breaks schema.create() #9928

Closed
tatupesonen opened this issue Feb 13, 2021 · 2 comments
Closed

Document<T = any> in index.d.ts breaks schema.create() #9928

tatupesonen opened this issue Feb 13, 2021 · 2 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@tatupesonen
Copy link

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

What is the current behavior?
Currently, Object.create() doesn't provide type completion except for the _id field.
Previously Document was set a class Document, now it is class Document<T = any>
The change happened in this commit

class Document<T = any> {

Last working version I tried this was with 5.11.7

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

Install 5.11.16, try to use schema.create(), types will be missing.

{
    "compilerOptions": {
        "allowJs": false,
        "module": "commonjs",
        "esModuleInterop": true,
        "target": "es5",
        "noImplicitAny": true,
        "skipLibCheck": true,
        "resolveJsonModule": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "@typeDefs/*": [
                "../shared/*"
            ],
        }
    },
    "include": [
        "src/**/*"
    ],
    "references": [
        {
            "path": "../shared"
        }
    ]
}

What is the expected behavior?
Editor provides types

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node v15.8.0, Mongoose 5.11.16, no database registered.

@LukasGerm
Copy link

The last version which works for me is 5.11.9. The version 5.11.10 or later is not working anymore.

@tatupesonen
Copy link
Author

import mongoose, { Mongoose } from "mongoose";

interface IUserModel {
  password: string;
  username: string;
}

// TODO Update reference to organization
const UserSchema = new mongoose.Schema({
    username: { type: String, required: true },
    password: { type: String, required: true }
});
const UserModel = mongoose.model<IUserModel & mongoose.Document>(
  "User",
  UserSchema
);

export default UserModel;

Using this as the schema
image
Example of autocompletion not working

@vkarpov15 vkarpov15 added this to the 5.11.18 milestone Feb 17, 2021
@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Feb 17, 2021
This was referenced Mar 5, 2021
This was referenced Mar 12, 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