Skip to content

Commit 743e80f

Browse files
morlayblakeembrey
authored andcommitted
Add documentation for fixing missing types (#627)
1 parent 55741b6 commit 743e80f

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

README.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
> TypeScript execution and REPL for node.js, with source map support. **Works with `typescript@>=2.0`**.
99
10-
**Tip:** `ts-node` differs slightly from `tsc`. It will not load files/includes/excludes from `tsconfig.json` by default. Instead, `ts-node` starts from the input file and discovers the rest of the project tree through imports and references. TypeScript provides [types](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types) and [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) functionality to resolve definitions.
11-
1210
## Installation
1311

1412
```sh
@@ -144,6 +142,38 @@ _Environment variable denoted in parentheses._
144142
* `readFile` Custom TypeScript-compatible file reading function
145143
* `fileExists` Custom TypeScript-compatible file existence function
146144

145+
## Help! My Types Are Missing!
146+
147+
**TypeScript Node** does _not_ use `files`, `include` or `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.
148+
149+
For global definitions, you can use [`typeRoots`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types):
150+
151+
```json
152+
{
153+
"compilerOptions": {
154+
"typeRoots" : ["./node_modules/@types", "./typings"]
155+
}
156+
}
157+
```
158+
159+
> A types package is a folder with a file called `index.d.ts` or a folder with a `package.json` that has a types field.
160+
> -- <cite>[TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types)</cite>
161+
162+
For module definitions, you can use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping):
163+
164+
```json
165+
{
166+
"compilerOptions": {
167+
"baseUrl": ".",
168+
"paths": {
169+
"custom-module-type": ["types/custom-module-type"]
170+
}
171+
}
172+
}
173+
```
174+
175+
**Tip:** If you _must_ use `files`, enable `--files` flags or set `TS_NODE_FILES=true`.
176+
147177
## Watching and Restarting
148178

149179
**TypeScript Node** compiles source code via `require()`, watching files and code reloads are out of scope for the project. If you want to restart the `ts-node` process on file change, existing node.js tools such as [nodemon](https://github.com/remy/nodemon), [onchange](https://github.com/Qard/onchange) and [node-dev](https://github.com/fgnass/node-dev) work.

0 commit comments

Comments
 (0)