wailsapp/wails · error

missing Type field in

Error message

missing Type field in 

What it means

Inside AddEnum, each slice element that is a struct is reflected upon and must expose a field named 'Value'; if the reflector cannot read r.Field("Value"), the generator panics with 'missing Type field in <Type>'. (The message text says 'Type' but the lookup is the Value field.) This defines the enum's numeric value in generated TypeScript.

Source

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

func (t *TypeScriptify) AddEnum(values interface{}) *TypeScriptify {
	if t.enums == nil {
		t.enums = map[reflect.Type][]enumElement{}
	}
	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)
	}

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Add an exported Value field to the enum struct (e.g. Value int)
  2. Ensure the field name is exactly 'Value' and exported
  3. Alternatively pass non-struct values that implement TSNamer

Example fix

// before
type Status struct{ TSName string }
ts.AddEnum([]Status{{"Active"}}) // panics: no Value field

// after
type Status struct {
    Value  int
    TSName string
}
ts.AddEnum([]Status{{0, "Active"}, {1, "Inactive"}})
Defensive patterns

Strategy: type-guard

Validate before calling

// verify required struct shape before registering
v := reflect.ValueOf(elements[0])
if v.Kind() == reflect.Struct {
    if _, ok := v.Type().FieldByName("Value"); !ok {
        return fmt.Errorf("enum struct %s needs exported Value field", v.Type())
    }
}

Type guard

type enumElement interface{ getValue() int; getTSName() string } // marker implemented by your enum structs
// plus compile-time check:
var _ = struct{ Value int; TSName string }{} // shape reminder for every enum struct

Prevention

When it happens

Trigger: Calling AddEnum with a slice of structs where the struct lacks an exported Value field (or the field exists but the reflector cannot access it).

Common situations: Feeding wails' typescriptify custom enum structs (e.g. additional system events enums) that define only Name/TSName but not Value, or where Value is unexported.

Related errors


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