You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I am creating a REST Api and when running the Node server getting the below error
error TS2339: Property 'isValid' does not exist on type 'ObjectIdConstructor'.
If the current behavior is a bug, please provide the steps to reproduce.
Below is my code
import express, { Request, Response } from 'express';
import mongoose from 'mongoose';
import {
User,
currentUser,
requireAuth,
RestrictToRoles,
NotFoundError,
} from '@ssomlk-org/distribution-common';
const router = express.Router();
router.delete(
'/api/users/disable-user/:userId',
currentUser,
requireAuth,
RestrictToRoles('developer', 'admin'),
async (req: Request, res: Response) => {
if (!mongoose.Types.ObjectId.isValid(req.params.userId)) {
throw new NotFoundError('User not found');
}
const existingUser = await User.findById(req.params.userId);
if (!existingUser) {
throw new NotFoundError('User not found');
}
existingUser.status = 'Inactive';
await existingUser.save();
const response = {
status: 'success',
data: {
user: existingUser,
},
};
res.status(204).send(response);
}
);
export { router as disableUserRouter };
Error is due to mongoose.Types.ObjectId.isValid(req.params.userId)
What is the expected behavior?
The server should run without any errors. This was working earlier but suddenly getting this error
NOTE: Not using @types/mongoose anymore
{
"compilerOptions": {
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
"strict": false /* Enable all strict type-checking options. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node:15.11.0-alpine3.13
mongoose: 5.13.7
typescript: 4.3.5
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I am creating a REST Api and when running the Node server getting the below error
error TS2339: Property 'isValid' does not exist on type 'ObjectIdConstructor'.
If the current behavior is a bug, please provide the steps to reproduce.
Below is my code
Error is due to mongoose.Types.ObjectId.isValid(req.params.userId)
What is the expected behavior?
The server should run without any errors. This was working earlier but suddenly getting this error
NOTE: Not using @types/mongoose anymore
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node:15.11.0-alpine3.13
mongoose: 5.13.7
typescript: 4.3.5
The text was updated successfully, but these errors were encountered: