Skip to content

Commit 879096a

Browse files
committed
Fix map keys if suffix/prefix specified
1 parent e9de7e5 commit 879096a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

typescriptify/typescriptify.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,14 @@ func (t *typeScriptClassBuilder) AddMapField(fieldName string, field reflect.Str
254254
}
255255
strippedFieldName := strings.ReplaceAll(fieldName, "?", "")
256256

257-
t.fields = append(t.fields, fmt.Sprintf("%s%s: {[key: %s]: %s};", t.indent, fieldName, t.prefix+keyType.Name()+t.suffix, valueTypeName))
257+
keyTypeStr := keyType.Name()
258+
// Key should always be string, no need for this:
259+
// _, isSimple := t.types[keyType.Kind()]
260+
// if !isSimple {
261+
// keyTypeStr = t.prefix + keyType.Name() + t.suffix
262+
// }
263+
264+
t.fields = append(t.fields, fmt.Sprintf("%s%s: {[key: %s]: %s};", t.indent, fieldName, keyTypeStr, valueTypeName))
258265
if valueType.Kind() == reflect.Struct {
259266
t.constructorBody = append(t.constructorBody, fmt.Sprintf("%s%sthis.%s = this.convertValues(source[\"%s\"], %s, true);", t.indent, t.indent, strippedFieldName, strippedFieldName, t.prefix+valueTypeName+t.suffix))
260267
} else {

0 commit comments

Comments
 (0)