Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit f37b5c7

Browse files
committed
Fix panic and get the value as recursive way
1 parent 05aae59 commit f37b5c7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

generator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,16 +911,20 @@ func tsprintField(v cue.Value, isType bool) (ts.Expr, error) {
911911
case cue.StructKind:
912912
switch op {
913913
case cue.SelectorOp, cue.AndOp, cue.NoOp:
914+
// Checks [string]something
914915
val := v.LookupPath(cue.MakePath(cue.AnyString))
915916
if val.Exists() {
917+
expr, err := tsprintField(val, isType)
918+
if err != nil {
919+
return nil, valError(v, err.Error())
920+
}
916921
kvs := []tsast.KeyValueExpr{
917922
{
918923
Key: ts.Ident("string"),
919-
Value: tsprintType(val.IncompleteKind()),
924+
Value: expr,
920925
CommentList: commentsFor(val.Value(), true),
921926
},
922927
}
923-
924928
return tsast.ObjectLit{Elems: kvs, IsType: isType, IsMap: true}, nil
925929
}
926930

testdata/map_to_type.txtar

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
-- cue --
22
package cuetsy
33

4+
#StructTest: {
5+
a: string
6+
}
7+
48
Map: {
59
boolTest: [string]: bool
610
numberTest: [string]: int64
711
stringTest: [string]: string
12+
emptyStructTest: {...}
13+
listTest: [string]: [...string]
14+
listWithStructTest: [string]: [...#StructTest]
15+
mapTest: [string]: [string]: string
16+
structTest: [string]: #StructTest
817
} @cuetsy(kind="interface")
918

19+
20+
1021
-- ts --
1122

1223
export interface Map {
1324
boolTest: Record<string, boolean>;
25+
emptyStructTest: Record<string, any>;
26+
listTest: Record<string, Array<string>>;
27+
listWithStructTest: Record<string, Array<{
28+
a: string,
29+
}>>;
30+
mapTest: Record<string, Record<string, string>>;
1431
numberTest: Record<string, number>;
1532
stringTest: Record<string, string>;
33+
structTest: Record<string, {
34+
a: string,
35+
}>;
1636
}

0 commit comments

Comments
 (0)