Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!