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
JavaScript Equivelant of declare in TypeScript

I have a line of code in my Next JS application that uses a variable from a script src in the app.tsx page like so

app.tsx:

<script src="https://js.stripe.com/v3/"></script>

config.ts:

declare var Stripe:any
const stripe = Stripe("stripe publishable key")

This works because TS doesn't recognize the variable Stripe, but at build time it's loaded in from the script and it can be initializes. The declare statement bypasses the error without giving the variable a previous value. But when the TypeScript is compiled to JS with npm run build, the declare statement disapears and I get an error before the build completes. So, are there any other ways I could bypass the error similare to a declare statement, or maybe a way of better importing the script?

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

0

this work fine becasuse the type "any" includes function type,and typescript is working before build,you should know typescript is a tool for convenience during development. the result of error is Stripe is a undefined varible,undefined variable can't be execute. so when execute the code,it will get error.so build tools can detect it,it nothing to do typescript. the right way is:

declare var Stripe:(value: string) => {...}
const stripe = Stripe("stripe publishable key")
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