.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tsutils / README.md
1 # Utility functions for working with typescript's AST\r
2 \r
3 [![Greenkeeper badge](https://badges.greenkeeper.io/ajafff/tsutils.svg)](https://greenkeeper.io/)\r
4 \r
5 ## Usage\r
6 \r
7 This package consists of two major parts: utilities and typeguard functions.\r
8 By importing the project you will get both of them.\r
9 ```js\r
10 import * as utils from "tsutils";\r
11 utils.isIdentifier(node); // typeguard\r
12 utils.getLineRanges(sourceFile); // utilities\r
13 ```\r
14 \r
15 If you don't need everything offered by this package, you can select what should be imported. The parts that are not imported are never read from disk and may save some startup time and reduce memory consumtion.\r
16 \r
17 If you only need typeguards you can explicitly import them:\r
18 ```js\r
19 import { isIdentifier } from "tsutils/typeguard";\r
20 // You can even distiguish between typeguards for nodes and types\r
21 import { isUnionTypeNode } from "tsutils/typeguard/node";\r
22 import { isUnionType } from "tsutils/typeguard/type";\r
23 ```\r
24 \r
25 If you only need the utilities you can also explicitly import them:\r
26 ```js\r
27 import { forEachComment, forEachToken } from "tsutils/util";\r
28 ```\r
29 \r
30 ### Typescript version dependency\r
31 \r
32 This package is backwards compatible with typescript 2.8.0 at runtime although compiling might need a newer version of typescript installed.\r
33 \r
34 Using `typescript@next` might work, but it's not officially supported. If you encounter any bugs, please open an issue.\r
35 \r
36 For compatibility with older versions of TypeScript typeguard functions are separated by TypeScript version. If you are stuck on `typescript@2.8`, you should import directly from the submodule for that version:\r
37 \r
38 ```js\r
39 // all typeguards compatible with typescript@2.8\r
40 import { isIdentifier } from "tsutils/typeguard/2.8";\r
41 // you can even use nested submodules\r
42 import { isIdentifier } from "tsutils/typeguard/2.8/node";\r
43 \r
44 // all typeguards compatible with typescript@2.9 (includes those of 2.8)\r
45 import { isIdentifier } from "tsutils/typeguard/2.9";\r
46 \r
47 // always points to the latest stable version (2.9 as of writing this)\r
48 import { isIdentifier } from "tsutils/typeguard";\r
49 import { isIdentifier } from "tsutils";\r
50 \r
51 // always points to the typeguards for the next TypeScript version (3.0 as of writing this)\r
52 import { isIdentifier } from "tsutils/typeguard/next";\r
53 ```\r
54 \r
55 Note that if you are also using utility functions, you should prefer the relevant submodule:\r
56 \r
57 ```js\r
58 // importing directly from 'tsutils' would pull in the latest typeguards\r
59 import { forEachToken } from 'tsutils/util';\r
60 import { isIdentifier } from 'tsutils/typeguard/2.8';\r
61 ```\r