0

Let's say I have a generic type like bellow

type GeneratePipeline<T = any> = {
        localField: keyof T;
    }

and interface User

interface User {
  email : string,
  password : string,
  generalInfo : {
    firstName: string
    lastName : string
    departmentId : string
  }
}

then I Create a type for GeneratePipeline by User

const UserPipeLine :GeneratePipeline<User>  = {
  localField : "generalInfo.departmentId"
}

Typescript throws an error at the line "generalInfo.departmentId".

How can I solve this issue? Thanks

2
  • Thanks for answer, but that's not my issue Commented May 19, 2023 at 4:25
  • 1
    typescriptlang.org/play?#code/… Commented May 19, 2023 at 5:36

1 Answer 1

0

You can create another interface for generalInfo and use it in the UserPipeLine.

interface GeneralInfo {
  firstName: string
  lastName : string
  departmentId : string
}

interface User {
  email : string,
  password : string,
  generalInfo: GeneralInfo
}

const UserPipeLine :GeneratePipeline<User & GeneralInfo>  = {
  localField : "departmentId"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I need that field have value generalInfo.departmentId because I will put that object into another parser function.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.