wailsapp/wails · error

missing TSName field in

Error message

missing TSName field in 

What it means

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.

Source

Thrown at v2/internal/typescriptify/typescriptify.go:362

	items := reflect.ValueOf(values)
	if items.Kind() != reflect.Slice {
		panic(fmt.Sprintf("Values for %T isn't a slice", values))
	}

	var elements []enumElement
	for i := 0; i < items.Len(); i++ {
		item := items.Index(i)

		var el enumElement
		if item.Kind() == reflect.Struct {
			r := reflector.New(item.Interface())
			val, err := r.Field("Value").Get()
			if err != nil {
				panic(fmt.Sprint("missing Type field in ", item.Type().String()))
			}
			name, err := r.Field("TSName").Get()
			if err != nil {
				panic(fmt.Sprint("missing TSName field in ", item.Type().String()))
			}
			el.value = val
			el.name = name.(string)
		} else {
			el.value = item.Interface()
			if tsNamer, is := item.Interface().(TSNamer); is {
				el.name = tsNamer.TSName()
			} else {
				panic(fmt.Sprint(item.Type().String(), " has no TSName method"))
			}
		}

		elements = append(elements, el)
	}
	slices.SortFunc(elements, func(a, b enumElement) int {
		return cmp.Compare(a.name, b.name)
	})
	ty := reflect.TypeOf(elements[0].value)

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Rename/add the exported TSName string field on the enum struct
  2. Match the exact capitalization TSName
  3. Or implement the TSNamer interface and pass non-struct values

Example fix

// before
type Status struct {
    Value int
    Name  string // wrong field name
}

// after
type Status struct {
    Value  int
    TSName string
}
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := reflect.TypeOf(el).FieldByName("TSName"); !ok {
    return fmt.Errorf("enum struct %s needs exported TSName field", reflect.TypeOf(el))
}
ts.AddEnum(elements)

Type guard

// compile-time shape check for each enum struct
type Status struct {
    Value  int
    TSName string
}
var _ = Status{Value: 0, TSName: ""} // field names enforced by the compiler

Prevention

When it happens

Trigger: Enum structs in the AddEnum slice that have a Value field but no exported TSName field.

Common situations: Hand-writing enum structs modeled on wails system-event enums but naming the label field 'Name' or 'Label' instead of 'TSName'.

Related errors


AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15). Data as JSON: /api/errors/595ef514b29308e2. Report an issue: GitHub.