Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda