wailsapp/wails · error

has no TSName method

Error message

 has no TSName method

What it means

For non-struct enum elements, AddEnum requires each element to implement the TSNamer interface (method TSName() string) to know its TypeScript member name; otherwise it panics with '<Type> has no TSName method'. This is the alternate path when enum values are plain named types rather than structs with Value/TSName fields.

Source

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

		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)
	t.enums[ty] = elements
	t.enumTypes = append(t.enumTypes, EnumType{Type: ty})

	return t
}

// AddEnumValues is deprecated, use `AddEnum()`
func (t *TypeScriptify) AddEnumValues(typeOf reflect.Type, values interface{}) *TypeScriptify {
	t.AddEnum(values)

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Implement func (e MyEnum) TSName() string on the enum type returning the TypeScript name
  2. Or switch to struct elements with exported Value and TSName fields

Example fix

// before
type Mode int
const (Read Mode = 0; Write Mode = 1)
ts.AddEnum([]Mode{Read, Write}) // panics

// after
func (m Mode) TSName() string { return [...]string{"Read","Write"}[m] }
ts.AddEnum([]Mode{Read, Write})
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := any(MyEnum(0)).(typescriptify.TSNamer); !ok {
    return fmt.Errorf("type %T must implement TSName() string", MyEnum(0))
}
ts.AddEnum([]MyEnum{...})

Type guard

func addNamedEnums[T typescriptify.TSNamer](t *typescriptify.TypeScriptify, vals ...T) {
    t.AddEnum(vals) // TSNamer constraint makes missing method a compile error
}

Prevention

When it happens

Trigger: Calling AddEnum([]MyEnum{...}) where MyEnum is a plain int/string type (or its elements) without a TSName() string method.

Common situations: Passing a slice of ordinary Go named-type constants expecting the generator to derive names from identifiers; reflection cannot see identifier names, so an explicit TSName method is mandatory.

Related errors


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