This lesson has been retired.
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


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

    John LindquistJohn Lindquist

    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".



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    00:00 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.

    00:19 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.

    00:41 This is a current limitation that should be solved by TypeScript 2.0coming 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.

    01:00 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.

    01:22 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.

    01:41 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.