⚠️ This lesson is retired and might contain outdated information.

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

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 5 years ago

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

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

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today