Skip to content

Commit 91cd642

Browse files
author
Boris Cherny
committed
Emit comments for literal unions (fix #475)
1 parent 34de194 commit 91cd642

File tree

4 files changed

+177073
-31690
lines changed

4 files changed

+177073
-31690
lines changed

src/generator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ function generateRawType(ast: AST, options: Options): string {
285285
* Generate a Union or Intersection
286286
*/
287287
function generateSetOperation(ast: TIntersection | TUnion, options: Options): string {
288-
const members = (ast as TUnion).params.map(_ => generateType(_, options))
288+
const members = (ast as TUnion).params.map(_ =>
289+
[_.comment ? generateComment(_.comment) : null, generateType(_, options)].filter(Boolean).join('\n')
290+
)
289291
const separator = ast.type === 'UNION' ? '|' : '&'
290292
return members.length === 1 ? members[0] : '(' + members.join(' ' + separator + ' ') + ')'
291293
}

test/__snapshots__/test/test.ts.md

Lines changed: 177064 additions & 31689 deletions
Large diffs are not rendered by default.

test/__snapshots__/test/test.ts.snap

194 KB
Binary file not shown.

test/e2e/enum.4.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const input = {
2+
oneOf: [
3+
{const: 'a', description: 'First comment (a).'},
4+
{const: 'b', description: 'Second comment (b).'}
5+
]
6+
}

0 commit comments

Comments
 (0)