Skip to content

Commit bddd1e1

Browse files
committed
Fix field doc placement
1 parent 90155a4 commit bddd1e1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

typescriptify/typescriptify.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func (t *TypeScriptify) convertType(depth int, typeOf reflect.Type, customCode m
587587
var err error
588588
fldOpts := t.getFieldOptions(typeOf, field)
589589
if fldOpts.TSDoc != "" {
590-
result += "\t/** " + fldOpts.TSDoc + " */\n"
590+
builder.addFieldDefinitionLine("/** " + fldOpts.TSDoc + " */")
591591
}
592592
if fldOpts.TSTransform != "" {
593593
t.logf(depth, "- simple field %s.%s", typeOf.Name(), field.Name)
@@ -805,6 +805,10 @@ func (t *typeScriptClassBuilder) addInitializerFieldLine(fld, initializer string
805805
t.constructorBody = append(t.constructorBody, fmt.Sprint(t.indent, t.indent, "this.", fld, " = ", initializer, ";"))
806806
}
807807

808+
func (t *typeScriptClassBuilder) addFieldDefinitionLine(line string) {
809+
t.fields = append(t.fields, t.indent+line)
810+
}
811+
808812
func (t *typeScriptClassBuilder) addField(fld, fldType string) {
809813
t.fields = append(t.fields, fmt.Sprint(t.indent, fld, ": ", fldType, ";"))
810814
}

typescriptify/typescriptify_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,8 @@ export class WithoutAnnotation {
995995
func TestTypescriptifyComment(t *testing.T) {
996996
t.Parallel()
997997
type Person struct {
998-
Name string `json:"name" ts_doc:"This is a comment"`
998+
Age int `json:"age" ts_doc:"Age comment"`
999+
Name string `json:"name" ts_doc:"Name comment"`
9991000
}
10001001

10011002
converter := New()
@@ -1005,7 +1006,9 @@ func TestTypescriptifyComment(t *testing.T) {
10051006
converter.CreateConstructor = false
10061007

10071008
desiredResult := `export class Person {
1008-
/** This is a comment */
1009+
/** Age comment */
1010+
age: number;
1011+
/** Name comment */
10091012
name: string;
10101013
}`
10111014
testConverter(t, converter, false, desiredResult, nil)

0 commit comments

Comments
 (0)