For NodeJS development, you would typically write it in Typescript - which has a very good type system.
Personally I have also written serverside C# code, which is a very nice experience these days. C# is a big language these days though.
type HorsePlay interface {
Neigh()
}
type SomeClass[T HorsePlay] struct {
players []T
}
func (sc SomeClass[T]) NeighAll() {
for _, p := range sc.players {
p.Neigh()
}
}
type Horse struct{}
func (h Horse) Neigh() {
fmt.Println("neigh!")
}
func main() {
sc := SomeClass[Horse]{players: []Horse{{}, {}, {}}}
sc.NeighAll()
}