This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

TypeScript - Using Exclude and RootDir until File Globs Lands in 2.0.

1:48 TypeScript lesson by

Files globs will be available in TypeScript 2.0, so in the meantime, we need to use "exclude" and "rootDir" to configure which files to load. This lesson shows how to switch from "files" to "exclude".


egghead.io comment guidelines

Avatar
egghead.io

Files globs will be available in TypeScript 2.0, so in the meantime, we need to use "exclude" and "rootDir" to configure which files to load. This lesson shows how to switch from "files" to "exclude".

Avatar
Danny

Unfortunately, TypeScript 2.1 is out but the problem is not solved.
Using "files": [ "./src/*.ts" ] still don't work as expected.

In reply to egghead.io

Unfortunately, files in the tsconfig does not support glob patterns. You can't use things like wildcards. What that means is in tooling, as in using WebStorm, or Code, or Atom, or any editor that supports the TypeScript language services based on the TypeScript compiler.

As you start importing other files, say I try to import this file into here, it wouldn't give me the code completion, or type checking, and things like that that you would expect unless you came in here, and you added another line, and you said another to include that file. Every time you edit a file, you'd have to keep on adding new files to this.

This is a current limitation that should be solved by TypeScript 2.0 coming out relatively soon. This still doesn't work in the compiler because a compile time main can look up all the files it references and output them. It's just that during tooling time, when you're actually writing code, it doesn't find all the references in that file.

Anyway, it's hard to reproduce and show, but you will run into it. The accepted alternative right now is, instead of declaring exactly which files you want, define the files that you want to exclude. You'll always want to exclude node modules. You don't want to look through every single file in node modules and compile them.

Also, in your Compiler Options, set up a root dir. We'll call this Source. We'll say look in the source directory as the root directory so that when you output the dist directory that it only outputs the files with that exact same folder structure.

From here on out, I'm going to leave it like this with Exclude. In the future, you will be able to use files with the glob patterns and wildcards.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?