Configuring TypeScript 16 exercises
solution

Extending a Base TypeScript Configuration

We'll start by creating a tsconfig.base.json file, which serves as our base TypeScript configuration.

It's important to note that this is not a working configuration file for TypeScript, and it will not be used to directly reference other TypeScript files. Instead, it acts as a base configuratio

Loading solution

Transcript

00:00 In the solution here, we have created a tsconfig.base.json. This could be named anything we want to. I kind of just like calling it .base.json because it indicates, first of all, that it's not a working tsconfig. So TypeScript itself won't look at this and go, ooh, I need to use this to reference

00:18 all of the other TypeScript files. It will pass over it. But we can use it to basically say, inside the client here, we can say that this tsconfig.json, which is something that TypeScript will check, extends this tsconfig.base.json, which lives above it. So this one will just inherit

00:36 all of the compiler options inside here. Inside the server, too, we basically do the same thing, but we just add in our extra compiler options that we need here. Beautiful stuff. Now, this works really nicely when you have, let's say, a monorepo, so many, many tsconfigs that you all need

00:55 to reference basically a single one. And this means that you can change a single value inside here, so restrict or no emit or whatever you like, and you can just basically make that inherit throughout the entire project. You can even have multiple of these. For instance, if you're operating in different environments, that's very, very common, too. So the extends property is really nice.

01:14 Now, make sure, though, that when you do this, that extends, like, extends will only copy the compiler options over, I'm pretty sure. So anything outside of this, like exclude, or like include, for instance, which lets you specify the files that you want to add into your TypeScript compilation, I'm pretty sure they won't be added. It's mainly just for compiler options.

01:33 But extends, very, very useful in these situations where you have lots of tsconfigs that you just want to have a base version of and then add extra properties to as you need them.