Configuring TypeScript 16 exercises

Managing Multiple tsconfig Files

The starting point for this exercise had client.ts, server.ts, and a tsconfig.json file side-by-side in the root of the project directory.

By default, TypeScript determines which tsconfig.json to use by looking for the closest one to the .ts file in question. If there are no other `tsc

Loading solution


00:00 Okay, the solution involves changing quite a lot of things inside the directory here. So in the problem setup, we just had source, client.ts, and server.ts, and we had a tsconfig in the root of the package. The way this works is that TypeScript will look, when it has some .ts files,

00:18 it will look at the closest tsconfig to it inside this root here. Because you notice, actually, in the entire repo, we actually have a tsconfig right at the root, which, if we don't have any directories in here, that's the tsconfig that's used by default.

00:32 But the files in here, client.ts and server.ts, they will actually use this one because it's closer to them. Let's look at the solution then. So the solution is we can actually mimic that by having a client folder here

00:46 and using index.ts inside it, and then in there have its own tsconfig.json. In this tsconfig.json, we're not specifying lib, so it defaults to including the DOM stuff in there. And inside the server here, we have another tsconfig.json where we specify lib,

01:03 and because we're specifying it, it won't contain document. So this means we get to change the tsconfig settings based on the directory we're in, and we're now using multiple tsconfig files. Very, very cool.