-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
bug: Not inferring Native error #10340
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
Comments
I just noticed that mongoose is written .js not in .ts, this is one of major reasons I think I have to file an issue like mine, may I know when this library being written in typescript? |
It already has a typescript support |
|
I only see types to model only after using any method such as find, update, findbyid non of definitions get shown in the callback. Also doesn't it easy to have automatic type definitions (.d.ts) files generated from typescript and bundler rather than keeping specific.d.ts files because that costs no? |
@Himadu2000 below code compiles without error, please modify the below script to demonstrate your issue. import * as mongoose from "mongoose";
mongoose.connect("mongodb://localhost:27017/test", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const Cat = mongoose.model("Cat", new mongoose.Schema({ name: String }));
const kitty = new Cat({ name: "Zildjian" });
kitty.save().then(() => console.log("meow"));
Cat.find({}, (error) => {
if (error) {
return error;
}
}); |
@vkarpov15 Okay, here's a example line where problem lies , in the line |
So @vkarpov15, what does err returns, I never got err but it needs to known to handle them, I can't take chances for unhandled errors on production app. |
What is the current behavior?
error TS7006: Parameter 'error' implicitly has an 'any' type.
steps to reproduce.
Repo to recreate
Run
yarn compile
Following action
Quick code
Cat.find({}, (error) => { if (error) { return error; } });
compile with
tsc --strict
What is the expected behavior?
Should infer NativeError in error
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: v14.17.0
"mongoose": "^5.12.13"
The text was updated successfully, but these errors were encountered: