File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,9 +15,54 @@ Default: `false`
1515When a literal value is thrown, document its base type rather than the literal type.
1616For 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
2038Default: ` true `
2139
2240When more than one exception can be thrown, the types are added as a union type in the comment.
2341If 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+ ```
Original file line number Diff line number Diff line change @@ -15,9 +15,54 @@ Default: `false`
1515When a literal value is thrown, document its base type rather than the literal type.
1616For 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
2038Default: ` true `
2139
2240When more than one exception can be thrown, the types are added as a union type in the comment.
2341If 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+ ```
You can’t perform that action at this time.
0 commit comments