Automattic / Automattic/mongoose
[Typscript] Wrong type for `new Model(doc)`
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 35
Description
**Do you want to request a *feature* or report a *bug*?**
bug
**What is the current behavior?**
When using `new Model(doc)` to create a new model and the `save()` it. the type of `doc` is always `any` which break the auto-completion for properties added by the user model.

**If the current behavior is a bug, please provide the steps to reproduce.**
[Quick Start](https://mongoosejs.com/docs/index.html) example from the website
`tsconfig.json`
```json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"moduleResolution": "node",
"types": ["mongoose"],
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules"],
"include": ["src/**/*.ts"]
}
```
**What is the expected behavior?**
instead of having `any` it should use the provided type.
**What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.**
nodejs: v16.1.0
mongoose: 5.12.10
Contributor guide
Research direction
Start with the Quick Start example from the Mongoose website and the provided tsconfig.json, then reproduce the type of doc passed to new Model(doc) and checked after save(). Trace the TypeScript model and document typings to identify where any is introduced. Done means the provided model type is preserved and property autocomplete works without any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, node.js, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100