TypeScript Node does not use
exclude, by default. This is because a large majority projects do not use all of the files in a project directory (e.g.
Gulpfile.ts, runtime vs tests) and parsing every file for types slows startup time. Instead,
ts-node starts with the script file (e.g.
ts-node index.ts) and TypeScript resolves dependencies based on imports and references.
For global definitions, you can use the
typeRoots compiler option. This requires that your type definitions be structured as type packages (not loose TypeScript definition files). More details on how this works can be found in the TypeScript Handbook.
Example project structure:
Example module declaration file:
For module definitions, you can use
An alternative approach for definitions of third-party libraries are triple-slash directives. This may be helpful if you prefer not to change your TypeScript
compilerOptions or structure your custom type definitions when using
typeRoots. Below is an example of the triple-slash directive as a relative path within your project:
Tip: If you must use
--files flags or set