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

225
Visualizações
How to check if an observable is of NEVER type?

I have a case in my angular application where I need to change the observable if the initial value was NEVER:

export class MyComponent {
  @Input() isInitiallyOpen$?: Observable<boolean> = NEVER;

  constructor(private myService: MyService) {
    this.isOpen$ = this.isInitiallyOpen$ ?? this.myService.isOpen$; // NOT WORKING
    // this.isOpen$ = NEVER at this point, and not this.myService.isOpen$
  }
}

I know that rxjs's NEVER is basically new Observable<never>(noop()). But my question is, is there any way to know that isInitiallyOpen$ stream is actually holding a NEVER value?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you check the NEVER Observable at the GitHub project you can see that its basically an empty Observable with a noop function:

export const NEVER = new Observable<never>(noop)

Therefore you can check if the variable equals NEVER. Below I made some tests for you to work with.

const { NEVER, Observable, noop } = rxjs;

const foo$ = NEVER
const bar$ = NEVER

console.log("foo$ === bar$: ", foo$ === bar$) // true
console.log("foo$ === NEVER: ", foo$ === NEVER) // true
console.log("foo$ === Observable: ", foo$ === Observable) // false
console.log("foo$ === new Observable(): ", foo$ === new Observable()) // false
console.log("foo$ === Observable(() => {}): ", foo$ === new Observable(() => {})) // false
console.log("foo$ === Observable(noop): ", foo$ === new Observable(noop)) // false
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.4.0/rxjs.umd.min.js"></script>

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