0

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

  • Welcome to Stack Overflow! Please [edit] the code to be a [mre] that will demonstrate your issue when others paste it into their own IDEs. Right now I just get a bunch of errors about missing types and values and imports I can't access. Oh and that title... do you mean "intersection" and not "insertion"? Good luck! – jcalz May 04 '23 at 15:18

0 Answers0