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

247
Visualizações
What is HasValue and .Value equivalent in TypeScript

I have a method :

public cancelOperation(OperationId: string): Promise<void> 
 {
         // some calls
 }

I get OperationId from another method :

let operationId = GetOperationId() {}

which return nullable OperationId,

 operationId?: string;

so when passing the OperationId received from GetOperationId(), I get error that operationId is nullable, so cant be used in method cancelOperation()

So is there any C# equivalent of

 operationId .Value 

or

operationId .HasValue 

method in Typescript so I could go for it.

Though we have option to check operationId like :

 cancelOperation(playAudioResult.operationId ? playAudioResult.operationId : "")

but I dont want to use it.

I need a solution which will something like : cancelOperation(operationId.?????)

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

if (operationId) will check for null in TypeScript. It will return true if the value is not null or undefined.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use if to check whether the operationI is null or not. Tho other way is nullish coalescing operator.

It is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined.

It carries out only if the value is not null like,

let x = operationI??NULL
about 4 years ago · Juan Pablo Isaza Relatório

0

Following the article shared by @ShamPooSham https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator

I got a way to get value from the nullable property as explained in the article.

We need to put ! after property and get the value(assuming that its not null)

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
  // Throw exception if e is null or invalid entity
}
function processEntity(e?: Entity) {
 validateEntity(e);
 let s = e!.name; // Assert that e is non-null and access name
}

Similary in my method I can use :

cancelOperation(playAudioResult.operationId!)  // notice the !
about 4 years ago · Juan Pablo Isaza 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