Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

81
Visualizações
Assigning an object to type interface but removing properties not included in the interface?

I have an object with additional properties but only want to return certain properties defined by an interface to the backend.

Is there a clean solution to this? I have checked online and a lot seem to refer to the Omit, Pick etc. utility methods. However, I have tried that but it returns all the properties of the object and does not omit/pick the required properties.

interface Student{
name: string;
age: number;
address: string;
}

an example object:

{name: "John Doe", age: 30, address: "123 ...", phoneNumber: "xxxxx", nextOfKin: "Marie Doe", ....}

I have tried:

type StudentInfoRequest = Omit<Student, "phoneNumber" | "nextOfKin">
type StudentInfoRequest = Pick<Student, "name" | "age" | "address">

when I assign it e.g.

let studentRequestList: StudentInfoRequest[] = [];

looping over the student objects to push into the studentRequestList and when I console log it includes the entire properties of the object rather than the interface only properties.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda