So the use case is a simple entity component system. What shirlyquirk posted comes quite close to what I want, and I think something like this is what I'll use. However, this requires me to manually "register" all component types in the ComponentManager, which I wanted to avoid.
Basically I hoped that type ImportantStuff = object littleMember[T]: seq[T] func get[T](a: ImportantStuff, i: int): T = a.littleMember[T][i] var c: ImportantStuff discard c.get[int](12) discard c.get[float](5) discard c.get[ComponenTypeA](5) Run would expand to type ImportantStuff = object littleMember_int: seq[int] littleMember_float: seq[float] littleMember_ComponentTypeA: seq[ComponentTypeA] func get[T](a: ImportantStuff, i: int): T = when T is float: a.littleMember_float[i] elif T is int: a.littleMember_int[i] elif T is ComponentTypeA: a.littleMember_ComponentTypeA var c: ImportantStuff discard c.get[int](12) discard c.get[float](5) discard c.get[ComponentTypeA](1) Run