0

I am trying to use a variable from a JavaScript file that gets downloaded via the <script> tag however typescript complains because it is undefined. I cannot define the variable otherwise it takes precedence and then I cannot access the other one.

Is there any way to do this?

1
  • Can you please share code of the second JavaScript file that get downloaded and include the variable you're trying to access? As there might be a chance that the variable you are trying to access have private scope. Commented Jun 18, 2018 at 17:49

1 Answer 1

1

Add:

declare var myVar;

to the beginning of your TypeScript file. This informs TypeScripts of its existence, without re-declaring it.

Sign up to request clarification or add additional context in comments.

1 Comment

My damn thank you so much. Have been banging my head for hours. Really appreciate it I will remember to do that when ever I use imported files. Wish I could give you 100 votes for pain you released me of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.