Skip to content

Commit 77eff53

Browse files
MicahZoltublakeembrey
authored andcommitted
Clarify global declarations in README (#698)
1 parent 3ff4a69 commit 77eff53

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

README.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,35 @@ _Environment variable denoted in parentheses._
146146

147147
**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.
148148

149-
For global definitions, you can use [`typeRoots`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types):
149+
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](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types).
150150

151-
```json
151+
Example `tsconfig.json`:
152+
153+
```
152154
{
153155
"compilerOptions": {
154156
"typeRoots" : ["./node_modules/@types", "./typings"]
155157
}
156158
}
157159
```
158160

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+
Example project structure:
162+
163+
```
164+
<project_root>/
165+
-- tsconfig.json
166+
-- typings/
167+
-- <module_name>/
168+
-- index.d.ts
169+
```
170+
171+
Example module declaration file:
172+
173+
```
174+
declare module '<module_name>' {
175+
// module definitions go here
176+
}
177+
```
161178

162179
For module definitions, you can use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping):
163180

0 commit comments

Comments
 (0)