Skip to content

Commit 1749daf

Browse files
authored
Merge pull request #141 from Xvezda/feature/docs
Add documentation examples
2 parents ac1d081 + 25e3b40 commit 1749daf

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

docs/rules/check-throws-tag-type.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,54 @@ Default: `false`
1515
When a literal value is thrown, document its base type rather than the literal type.
1616
For example, for `throw "foo"`, insert `@throws {string}` instead of `@throws {"foo"}`.
1717

18+
```ts
19+
// useBaseTypeOfLiteral: true
20+
/**
21+
* @throws {string}
22+
*/
23+
function test() {
24+
throw 'foo';
25+
}
26+
27+
// useBaseTypeOfLiteral: false
28+
/**
29+
* @throws {'foo'}
30+
*/
31+
function test() {
32+
throw 'foo';
33+
}
34+
```
35+
1836
### `preferUnionType`
1937

2038
Default: `true`
2139

2240
When more than one exception can be thrown, the types are added as a union type in the comment.
2341
If set to `false`, each exception is written on its own line.
42+
43+
```ts
44+
// preferUnionType: true
45+
/**
46+
* @throws {FooError | BarError}
47+
*/
48+
function test() {
49+
if (Math.random() < 0.5) {
50+
throw new FooError();
51+
} else {
52+
throw new BarError();
53+
}
54+
}
55+
56+
// preferUnionType: false
57+
/**
58+
* @throws {FooError}
59+
* @throws {BarError}
60+
*/
61+
function test() {
62+
if (Math.random() < 0.5) {
63+
throw new FooError();
64+
} else {
65+
throw new BarError();
66+
}
67+
}
68+
```

docs/rules/no-undocumented-throws.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,54 @@ Default: `false`
1515
When a literal value is thrown, document its base type rather than the literal type.
1616
For example, for `throw "foo"`, insert `@throws {string}` instead of `@throws {"foo"}`.
1717

18+
```ts
19+
// useBaseTypeOfLiteral: true
20+
/**
21+
* @throws {string}
22+
*/
23+
function test() {
24+
throw 'foo';
25+
}
26+
27+
// useBaseTypeOfLiteral: false
28+
/**
29+
* @throws {'foo'}
30+
*/
31+
function test() {
32+
throw 'foo';
33+
}
34+
```
35+
1836
### `preferUnionType`
1937

2038
Default: `true`
2139

2240
When more than one exception can be thrown, the types are added as a union type in the comment.
2341
If set to `false`, each exception is written on its own line.
42+
43+
```ts
44+
// preferUnionType: true
45+
/**
46+
* @throws {FooError | BarError}
47+
*/
48+
function test() {
49+
if (Math.random() < 0.5) {
50+
throw new FooError();
51+
} else {
52+
throw new BarError();
53+
}
54+
}
55+
56+
// preferUnionType: false
57+
/**
58+
* @throws {FooError}
59+
* @throws {BarError}
60+
*/
61+
function test() {
62+
if (Math.random() < 0.5) {
63+
throw new FooError();
64+
} else {
65+
throw new BarError();
66+
}
67+
}
68+
```

0 commit comments

Comments
 (0)