Configuring TypeScript 16 exercises
explainer

Globals are Tied to a Single Configuration

Another useful feature of having multiple tsconfig files is that globals are tied to a single configuration.

Let's look at an example.

First, we have a server.d.ts file in our server directory that declares a global constant ONLY_AVAILABLE_ON_SERVER:


// server/server.d.ts
declare co

Loading explainer

Transcript

00:00 Another useful thing about having multiple tsconfig files is that globals are tied to a single tsconfig. Inside our server, we have a server.d.ts, which is saying declare const onlyAvailableOnServer.

00:13 This is a string, and this means that inside this file here, we can use onlyAvailableOnServer as this global here. But if we go back to the client here, then onlyAvailableOnServer is not available. It's not available in the global scope.

00:28 This can be really useful when you have environment variables that are only available in a single environment that you want to be tied down to a single spot. Or if you have other sorts of globals, like globals imported from tests, so for instance Jest or Cypress or something like that, this means that they're only available in the environment that you need them to be.