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

vy.pham
  • 571
  • 6
  • 20
  • Thanks for answer, but that's not my issue – vy.pham May 19 '23 at 04:25
  • 1
    https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcBKwDGBXKBnASwDdgBpYRAeQDMAeAFUoCMArOUGYAOwBM84IrLDAB8cALxwA3gCg4cANr1yiOAS5wA1hQjU4jVnABkcABR4YUdQHM4AHzhdsAWybAoASgC6ALjnz9ZhYlFS92EE5efgBDLkQFMIB+OAADABIpZQoAXxS4PwDA1hCKMI5uPgEhTBh-QuT0zJVc+1SMrMRsgDoMjBx8YjIKGgYgksQvEVy6gJ82ppyUgG4ZbIVtRF0ithNzSxtWp1d3bxWZJBQ4AHFud2jOAAUCFAAbdWAGcMjKwRZhMUkskKLwgmGiLwAYgRgC8eHM+rhCCQVCN6CJVjMZOpOFBqNFMKgAKp4dzSfzAZzRAgvfJwCxWLjWAA0-jA0TweAA7tAeLT6TYWfJrLcoOCAJJcagQWlAgLUAj4GAAOWizmAc35jJmL3ZytVqA1+y1hR4wDZsDVXBgYt5hoZ1n82QxMhewHgxPcTxQABl3vkblw7o9njD3rQPVAAWT5CCwZDobC5gByYWB0UvCVSrqm80wS3WnhJ1ZAA – Andy Ray May 19 '23 at 05:36

1 Answers1

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"
}
Rinkesh Golwala
  • 979
  • 1
  • 7
  • 17
  • Hi, I need that field have value generalInfo.departmentId because I will put that object into another parser function. – vy.pham May 19 '23 at 05:07