Original post

I’m working on a terminal ui application using this library and here is the snippet of code that I’m trying to DRY up:

// cw is type Drawable, which is an interface that a bunch of 
// widget pointers implement i.e. *widget.List, *widget.Gauge, etc.

// All of these widgets are composed of another embedded type, Block,
// which gives them all the identical property, BorderStyle.

switch cw := currentWidget.(type) {
case *widgets.List:
        cw.BorderStyle.Fg = ui.ColorWhite
        ui.Render(cw)
case *widgets.Gauge:
        cw.BorderStyle.Fg = ui.ColorWhite
        ui.Render(cw)
case *widgets.Paragraph:
        cw.BorderStyle.Fg = ui.ColorWhite
        ui.Render(cw)
}

Basically what I’d love to be able to do it simply:

cw := currentWidget.(type)
cw.BorderStyle.Fg = ui.ColorWhite
ui.Render(cw)

—but of course I run into the error that says that I can’t use this form of type assertion outside of a switch statement but you get my point. Is there a way to achieve this?

Further context if necessary.