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

294
Visualizações
What is the difference between declare var and declare const in typescript definitions?

I recently had a few global variables that I was referencing from a TypeScript file that TypeScript marked with the following error:

Property 'msSpeechRecognition' does not exist on type 'Window & typeof globalThis'.

So I created added the following code into my env.d.ts (generated and referenced in tsconfig.json by create-vue):

declare const msSpeechRecognition: undefined | SpeechRecognitionStatic;

This didn't fix the problem. However, when I switched the code to the following:

declare var msSpeechRecognition: undefined | SpeechRecognitionStatic;

The error on the reference to msSpeechRecognition disappeared. I understand the differences between const and var in JavaScript, but what are the differences when using them in type declarations?

I couldn't reproduce this same issue when replacing SpeechRecognitionStatic with string, so I know it's something related to the SpeechRecognitionStatic type. Here is how it looked like (brought from @types/webspeechapi):

interface SpeechRecognitionStatic {
    prototype: SpeechRecognition;
    new (): SpeechRecognition;
}
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The error indicates that msSpeechRecognition is being accessed from the window object as window.msSpeechRecognition. You can only add something to globalThis by declaring it with var. If you want to use const instead, you will need to replace references to window.msSpeechRecognition with just msSpeechRecognition.

about 4 years ago · Santiago Gelvez 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