#Mongoose InjectModel weird error
22 messages · Page 1 of 1 (latest)
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { User, UserDocument } from 'src/schemas/user.schema';
@Injectable()
export class UserService {
constructor(
@InjectModel(User.name) private readonly userModel: Model<UserDocument>,
) {}
}
Unable to resolve signature of parameter decorator when called as an expression.
Argument of type 'undefined' is not assignable to parameter of type 'string | symbol'.ts(1239)
This error is on injectModel, I legit copypasted docs and it gives this weird error
Folder structure
import { Prop,Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';
export type UserDocument = HydratedDocument<User>;
@Schema()
export class User {
@Prop()
name: string;
@Prop()
username: string;
@Prop()
password: string;
}
export const UserSchema = SchemaFactory.createForClass(User);
user.schema.ts
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from 'src/schemas/user.schema';
@Module({
imports: [
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
],
controllers: [UserController],
providers: [UserService],
})
export class UserModule {}
user.module.ts
For me, it looks like its a typescript problem. Are you using any typescript extension?
Can you open vscode, hit CTRL+SHIFT+P and type "TypeScript: Select TypeScript version"
an send me a screenshot
Can you select workspace version and test again?
all of us already passed that type of situation 😅
thank you a lot man