wailsapp/wails · error
Values for %T isn't a slice
Error message
Values for %T isn't a slice
What it means
TypeScriptify.AddEnum panics when the value passed via AddEnum(values interface{}) is not a reflect.Slice. The method uses reflection over an untyped interface{}, so a non-slice argument (a map, array is fine as slice-kind? no—only slice kind passes, arrays have Kind Array) cannot be iterated as enum elements.
Source
Thrown at v2/internal/typescriptify/typescriptify.go:346
}
}
t.fields = append(t.fields, fmt.Sprintf("%s%s: Record<%s, %s>;", t.indent, fieldName, keyTypeStr, valueTypePrefix+valueTypeName+valueTypeSuffix))
if valueType.Kind() == reflect.Struct {
t.constructorBody = append(t.constructorBody, fmt.Sprintf("%s%sthis%s = this.convertValues(source[\"%s\"], %s, true);",
t.indent, t.indent, dotField, strippedFieldName, t.prefix+valueTypePrefix+valueTypeName+valueTypeSuffix+t.suffix))
} else {
t.constructorBody = append(t.constructorBody, fmt.Sprintf("%s%sthis%s = source[\"%s\"];",
t.indent, t.indent, dotField, strippedFieldName))
}
}
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 = valView on GitHub (pinned to 0e754b1b40)
Solutions
- Pass a slice: []MyEnum{...} rather than an array, map, or single value
- If the value arrives dynamically, check reflect.ValueOf(v).Kind() == reflect.Slice before calling AddEnum
Example fix
// before
ts.AddEnum(MyEnum{}) // struct: panics
ts.AddEnum([3]MyEnum{}) // array: panics
// after
ts.AddEnum([]MyEnum{A, B, C}) Defensive patterns
Strategy: validation
Validate before calling
if reflect.ValueOf(values).Kind() != reflect.Slice {
return fmt.Errorf("AddEnum needs a slice, got %T", values)
}
ts.AddEnum(values) Type guard
func addEnumSlice[T any](t *typescriptify.TypeScriptify, values []T) {
// []T is always Slice kind; misuse becomes a compile error
t.AddEnum(values)
} Prevention
- Pass a []MyEnum literal, not an array, map, or single value
- Wrap AddEnum calls behind a generic helper constrained to slices
When it happens
Trigger: Calling AddEnum with a single value, a map, an array ([N]T has Kind Array, not Slice), or a pointer to a slice instead of a slice.
Common situations: Extending the wails binding generator with custom enums and passing e.g. an enum map[string]int, one struct value, or a [3]MyEnum array instead of []MyEnum.
Related errors
- missing Type field in
- missing TSName field in
- has no TSName method
- binding method ID registration expects a function, got %s
- use ShowAndGetResults for open multiple files dialog
AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15).
Data as JSON: /api/errors/6ce8910e232dcd52.
Report an issue: GitHub.