Skip to content

Commit 86f15ec

Browse files
Basarat Ali SyedBasarat Ali Syed
Basarat Ali Syed
authored and
Basarat Ali Syed
committed
rudimentary type docs. Closes #148
1 parent f2c7af1 commit 86f15ec

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* [Browser QuickStart](docs/quick/browser.md)
3737
* [TypeScript's Type System](docs/types/type-system.md)
3838
* [JS Migration Guide](docs/types/migrating.md)
39+
* [@types](docs/types/@types.md)
3940
* [Ambient Declarations](docs/types/ambient/intro.md)
4041
* [Declaration Files](docs/types/ambient/d.ts.md)
4142
* [Variables](docs/types/ambient/variables.md)

docs/types/@types.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# `@types`
2+
3+
[Definitely Typed](https://github.com/DefinitelyTyped/DefinitelyTyped) is definitely one of TypeScript's greatest strengths. The community has effectively gone ahead and **documented** the nature of nearly 90% of the top JavaScript projects out there.
4+
5+
This means that you can use these projects in a very interactive an exploratory manner, no need to have the docs open in a seperate window and making sure you don't make a typo.
6+
7+
## Using `@types`
8+
9+
Installation is fairly simple as it just works on top of `npm`. So as an example you can install type definitions for `jquery` simply as :
10+
11+
```
12+
npm install @types/jquery --save-dev
13+
```
14+
15+
`@types` supports both *global* and *module* type definitions.
16+
17+
18+
### Global `@types`
19+
20+
After installation, to use a type definition globally you simply add it to your tsconfig.json e.g. to use jquery
21+
22+
```
23+
{
24+
"compilerOptions": {
25+
"types": [
26+
"jquery"
27+
]
28+
}
29+
}
30+
```
31+
32+
Now you should be able to use `$` or `jQuery` *globally* in your project.
33+
34+
> Alternatively, if you don't include it in tsconfig.json, you can use it only in particular files simply by adding `/// <reference types="jquery" />` to the top of that file. (I personally don't do this).
35+
36+
For *libraries* I generally recommend using *modules*:
37+
38+
### Module `@types`
39+
40+
After installation, no special configuration required really. You just use it like a module e.g.
41+
42+
```
43+
import * as $ from "jquery";
44+
45+
// Use $ at will in this module :)
46+
```

0 commit comments

Comments
 (0)