1

If we have some environment variables which are present in the environment in which the compiled JavaScript is going to run, how we can mention those variables in Typescript code ?

In TypeScript varaibles cannot be used without being declared. If it is declared like let env_varaible;, it become var env_variable; which eventually overridethe actual varaible. What is the solution for this?

2
  • So why you can use just env.variable? Commented Nov 9, 2016 at 13:25
  • during compilation typescript will show - error TS2304: Cannot find name 'env_variable'. Commented Nov 9, 2016 at 13:28

1 Answer 1

2

You can tell TypeScript about a variable created by globals (coming directly from JavaScript runtime environment or any external source) with:

declare var env_variable;

Typescript won't throw an error for undeclared env_variable variable.

See also: declare global namespace variable from TypeScript

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

Comments

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.