Skip to content

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

Closed
Himadu2000 opened this issue Jun 9, 2021 · 7 comments
Closed

bug: Not inferring Native error #10340

Himadu2000 opened this issue Jun 9, 2021 · 7 comments
Assignees
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@Himadu2000
Copy link

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"

@IslandRhythms IslandRhythms added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Jun 9, 2021
@Himadu2000
Copy link
Author

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?

@IslandRhythms
Copy link
Collaborator

It already has a typescript support
https://mongoosejs.com/docs/typescript.html

@IslandRhythms IslandRhythms added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Jun 14, 2021
@IslandRhythms
Copy link
Collaborator

import * as mongoose from "mongoose";

interface User{
    name: string;
}

const schema = new mongoose.Schema<User>({name: String});

mongoose.connect("mongodb://localhost:27017/test", {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const Cat = mongoose.model("Cat", schema);

const kitty = new Cat({ name: "Zildjian" });
kitty.save().then(() => console.log("meow"));

Cat.find({}, (error) => {
  if (error) {
    return error;
  }
});

@IslandRhythms IslandRhythms removed the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Jun 14, 2021
@Himadu2000
Copy link
Author

Himadu2000 commented Jun 14, 2021

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?

@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Jun 14, 2021
@vkarpov15 vkarpov15 added this to the 5.12.14 milestone Jun 14, 2021
@vkarpov15
Copy link
Collaborator

@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 vkarpov15 removed this from the 5.12.14 milestone Jun 14, 2021
@vkarpov15 vkarpov15 added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Jun 14, 2021
@Himadu2000
Copy link
Author

@vkarpov15 Okay, here's a example line where problem lies , in the line callback?: (err: any, the err is type of any, so it needs to be either string or different type which I am not sure what return.

@Himadu2000
Copy link
Author

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.

@vkarpov15 vkarpov15 added this to the 5.12.15 milestone Jun 17, 2021
@vkarpov15 vkarpov15 removed the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Jun 17, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.12.15, 5.12.16 Jun 23, 2021
@vkarpov15 vkarpov15 assigned IslandRhythms and unassigned vkarpov15 Jun 30, 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