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

231
Visualizações
Why is the Bitwise OR operator being used in a variable declaration?

I'm learning Angular and reading through the documentation but I'm confused why the bitwise OR operator is being used in the product variable declaration below. What does the product: Product | undefined line mean?

export class ProductDetailsComponent implements OnInit {

  product: Product | undefined;
  /* ... */
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In that context it is not the OR operator but a "Union Type".

In TypeScript, a union type variable is a variable which can store multiple type of values (i.e. number, string etc).

A union type allows us to define a variable with multiple types. The union type variables are defined using the pipe ('|') symbol between the types.

Source: https://howtodoinjava.com/typescript/union-types/

So this means that product must be of type Product or undefined. (the undefined part is only relevant if you have strictNullChecks enabled).

Another way to write this is

product?: Product;

Where the question mark indicates that it is an optional parameter.

over 4 years ago · Santiago Trujillo Relatório
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