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

261
Visualizações
[Syntax Help]What is "variable : () => " meaning in Typescript or JavaScript

I was reading a source code about next-firebase-auth.

I am confused about the following code syntax

export const useAuthUser: () => AuthUserContext

export const verifyIdToken: (token: string) => Promise<AuthUser>

The right side look like an arrow function. The left side is declaring varibles. Intuitively, I am thinking is the same as the following:

export const useAuthUser = () => AuthUserContext

However, it doesn't. I did some test on Chrome console. Here is the code

adder : () => (a + b)

When I hit enter, it shows

() => (a+b)

But If I type adder, it shows

Uncaught ReferenceError: adder is not defined

I looked other posts here. It seems like the colon (:) is related to type annotation. So does it mean the right side is a type or interface? But how is an arrow function type or interface? It does not make sense.

Thanks for your help!

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

0

The stuff after the colon is the type. As a type, () => AuthUserContext means a function that doesn't require any arguments, and which returns an AuthUserContext. (token: string) => Promise<AuthUser> Means a function that requires a single argument which is a string, and then returns a Promise that will resolve to an AuthUser

The lines of code you showed seem incomplete. Typically, a const will immediately followed by an assignment, as in:

export const useAuthUser: () => AuthUserContext = () => {
  // some code which returns an AuthUserContext
}

I did some test on Chrome console.

The console only supports javascript, not typescript

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