Globals 4 exercises
Problem

Add Types to Properties of Global Namespaced Interfaces

In this exercise, we will be typing the process.env variable from NodeJS.

Adding types for process.env will allow us to get autocompletion for any environment variables that are set.

Challenge

Your challenge is to use declare global and add a MY_ENV_VAR property to the ProcessEnv inter

Loading exercise

Transcript

0:00 In this exercise, we're going to be typing process.env. Process.env is basically taken from types node. What this is doing is we've got this thing here called nodeJS.process and what we're trying to do is basically get autocomplete for the environment variables that are on there.

0:20 You can see that my solution environment variable is coming in to spoil the party, showing that I do have something attached to the global there. We're expecting process.env.MY_ENV_VAR to equal hello, world, which we're assigning there.

0:32 We're also expecting it to be type of string not type of string or undefined. We're going to need declare global again. You're going to need to use the NodeJS namespace and inside the NodeJS namespace, there's a ProcessEnv interface.

0:48 This is our first chance looking at namespaces and I'm going to leave it there. You can check out the documentation for namespace and see how it works, but hopefully you should be able to intuit your way there. It's not too tricky this one.