I was trying to develop the backend for my website and while creating a custom type to include the property token in the createUserType I got an error stating
Type 'createUserType' is not assignable to type 'userType'. Property 'token' is missing in type 'createUserType' but required in type '{ token: string }'
I was trying just to insert the property token in the existing createUserType
Code in createUser.types.ts
import { UserEntity } from "src/users/user.entity";
type createUserType= Omit<UserEntity,"hashPassword"> ;
type userType = createUserType & { token: string };
export {createUserType,userType};
Code in users.services.ts
async buildUserResponse(userData:createUserType):Promise<userType>{
const token=this.generateJWT(userData.id,userData.email,userData.username);
Object.assign(userData,{token});
return userData;
}
Error message in above line :-
Type 'createUserType' is not assignable to type 'userType'. Property 'token' is missing in type 'createUserType' but required in type '{ token: string; }'.ts(2322)
I was thinking the property to work correctly but it didn't