{"record":{"id":"6ce8910e232dcd52","repo":"wailsapp/wails","slug":"values-for-t-isn-t-a-slice","errorCode":null,"errorMessage":"Values for %T isn't a slice","messagePattern":"Values for %T isn't a slice","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v2/internal/typescriptify/typescriptify.go","lineNumber":346,"sourceCode":"\t\t}\n\t}\n\tt.fields = append(t.fields, fmt.Sprintf(\"%s%s: Record<%s, %s>;\", t.indent, fieldName, keyTypeStr, valueTypePrefix+valueTypeName+valueTypeSuffix))\n\tif valueType.Kind() == reflect.Struct {\n\t\tt.constructorBody = append(t.constructorBody, fmt.Sprintf(\"%s%sthis%s = this.convertValues(source[\\\"%s\\\"], %s, true);\",\n\t\t\tt.indent, t.indent, dotField, strippedFieldName, t.prefix+valueTypePrefix+valueTypeName+valueTypeSuffix+t.suffix))\n\t} else {\n\t\tt.constructorBody = append(t.constructorBody, fmt.Sprintf(\"%s%sthis%s = source[\\\"%s\\\"];\",\n\t\t\tt.indent, t.indent, dotField, strippedFieldName))\n\t}\n}\n\nfunc (t *TypeScriptify) AddEnum(values interface{}) *TypeScriptify {\n\tif t.enums == nil {\n\t\tt.enums = map[reflect.Type][]enumElement{}\n\t}\n\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","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v2/internal/typescriptify/typescriptify.go#L328-L364","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nts.AddEnum(MyEnum{})         // struct: panics\nts.AddEnum([3]MyEnum{})      // array: panics\n\n// after\nts.AddEnum([]MyEnum{A, B, C})","handlingStrategy":"validation","validationCode":"if reflect.ValueOf(values).Kind() != reflect.Slice {\n    return fmt.Errorf(\"AddEnum needs a slice, got %T\", values)\n}\nts.AddEnum(values)","typeGuard":"func addEnumSlice[T any](t *typescriptify.TypeScriptify, values []T) {\n    // []T is always Slice kind; misuse becomes a compile error\n    t.AddEnum(values)\n}","tryCatchPattern":null,"preventionTips":["Pass a []MyEnum literal, not an array, map, or single value","Wrap AddEnum calls behind a generic helper constrained to slices"],"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"}