{"record":{"id":"595ef514b29308e2","repo":"wailsapp/wails","slug":"missing-tsname-field-in","errorCode":null,"errorMessage":"missing TSName field in ","messagePattern":"missing TSName field in ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v2/internal/typescriptify/typescriptify.go","lineNumber":362,"sourceCode":"\titems := reflect.ValueOf(values)\n\tif items.Kind() != reflect.Slice {\n\t\tpanic(fmt.Sprintf(\"Values for %T isn't a slice\", values))\n\t}\n\n\tvar elements []enumElement\n\tfor i := 0; i < items.Len(); i++ {\n\t\titem := items.Index(i)\n\n\t\tvar el enumElement\n\t\tif item.Kind() == reflect.Struct {\n\t\t\tr := reflector.New(item.Interface())\n\t\t\tval, err := r.Field(\"Value\").Get()\n\t\t\tif err != nil {\n\t\t\t\tpanic(fmt.Sprint(\"missing Type field in \", item.Type().String()))\n\t\t\t}\n\t\t\tname, err := r.Field(\"TSName\").Get()\n\t\t\tif err != nil {\n\t\t\t\tpanic(fmt.Sprint(\"missing TSName field in \", item.Type().String()))\n\t\t\t}\n\t\t\tel.value = val\n\t\t\tel.name = name.(string)\n\t\t} else {\n\t\t\tel.value = item.Interface()\n\t\t\tif tsNamer, is := item.Interface().(TSNamer); is {\n\t\t\t\tel.name = tsNamer.TSName()\n\t\t\t} else {\n\t\t\t\tpanic(fmt.Sprint(item.Type().String(), \" has no TSName method\"))\n\t\t\t}\n\t\t}\n\n\t\telements = append(elements, el)\n\t}\n\tslices.SortFunc(elements, func(a, b enumElement) int {\n\t\treturn cmp.Compare(a.name, b.name)\n\t})\n\tty := reflect.TypeOf(elements[0].value)","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v2/internal/typescriptify/typescriptify.go#L344-L380","documentation":"After successfully reading the Value field, AddEnum requires a second exported struct field named 'TSName' which supplies the generated TypeScript enum member name; its absence panics with 'missing TSName field in <Type>'. Together Value + TSName form the required struct shape for enum elements.","triggerScenarios":"Enum structs in the AddEnum slice that have a Value field but no exported TSName field.","commonSituations":"Hand-writing enum structs modeled on wails system-event enums but naming the label field 'Name' or 'Label' instead of 'TSName'.","solutions":["Rename/add the exported TSName string field on the enum struct","Match the exact capitalization TSName","Or implement the TSNamer interface and pass non-struct values"],"exampleFix":"// before\ntype Status struct {\n    Value int\n    Name  string // wrong field name\n}\n\n// after\ntype Status struct {\n    Value  int\n    TSName string\n}","handlingStrategy":"type-guard","validationCode":"if _, ok := reflect.TypeOf(el).FieldByName(\"TSName\"); !ok {\n    return fmt.Errorf(\"enum struct %s needs exported TSName field\", reflect.TypeOf(el))\n}\nts.AddEnum(elements)","typeGuard":"// compile-time shape check for each enum struct\ntype Status struct {\n    Value  int\n    TSName string\n}\nvar _ = Status{Value: 0, TSName: \"\"} // field names enforced by the compiler","tryCatchPattern":null,"preventionTips":["Name the label field exactly TSName (capital T, capital S, capital N)","Keep Value and TSName side by side and exported in every enum struct"],"tags":["typescript","bindings","reflection","api-misuse","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}