Skip to content

Commit

Permalink
rudimentary type docs. Closes #148
Browse files Browse the repository at this point in the history
  • Loading branch information
Basarat Ali Syed authored and Basarat Ali Syed committed Oct 8, 2016
1 parent f2c7af1 commit 86f15ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [Browser QuickStart](docs/quick/browser.md)
* [TypeScript's Type System](docs/types/type-system.md)
* [JS Migration Guide](docs/types/migrating.md)
* [@types](docs/types/@types.md)
* [Ambient Declarations](docs/types/ambient/intro.md)
* [Declaration Files](docs/types/ambient/d.ts.md)
* [Variables](docs/types/ambient/variables.md)
Expand Down
46 changes: 46 additions & 0 deletions docs/types/@types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# `@types`

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

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.

## Using `@types`

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 :

```
npm install @types/jquery --save-dev
```

`@types` supports both *global* and *module* type definitions.


### Global `@types`

After installation, to use a type definition globally you simply add it to your tsconfig.json e.g. to use jquery

```
{
"compilerOptions": {
"types": [
"jquery"
]
}
}
```

Now you should be able to use `$` or `jQuery` *globally* in your project.

> 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).
For *libraries* I generally recommend using *modules*:

### Module `@types`

After installation, no special configuration required really. You just use it like a module e.g.

```
import * as $ from "jquery";
// Use $ at will in this module :)
```

0 comments on commit 86f15ec

Please sign in to comment.