Skip to content

Commit 1856bab

Browse files
committed
pass along zmodel type comments to generated TS types
1 parent ab046df commit 1856bab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/schema/src/plugins/enhancer/enhance/model-typedef-generator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ export function generateTypeDefType(sourceFile: SourceFile, decl: TypeDef) {
88
sourceFile.addTypeAlias({
99
name: decl.name,
1010
isExported: true,
11+
docs: decl.comments.map((c) => unwrapTripleSlashComment(c)),
1112
type: (writer) => {
1213
writer.block(() => {
1314
decl.fields.forEach((field) => {
15+
if (field.comments.length > 0) {
16+
writer.writeLine(` /**`);
17+
field.comments.forEach((c) => writer.writeLine(` * ${unwrapTripleSlashComment(c)}`));
18+
writer.writeLine(` */`);
19+
}
1420
writer.writeLine(
15-
`${field.name}${field.type.optional ? '?' : ''}: ${zmodelTypeToTsType(field.type)};`
21+
` ${field.name}${field.type.optional ? '?' : ''}: ${zmodelTypeToTsType(field.type)};`
1622
);
1723
});
1824
});
1925
},
2026
});
2127
}
2228

29+
function unwrapTripleSlashComment(c: string): string {
30+
return c.replace(/^[/]*\s*/, '');
31+
}
32+
2333
function zmodelTypeToTsType(type: TypeDefFieldType) {
2434
let result: string;
2535

0 commit comments

Comments
 (0)