Type cannot be used as values in Nim.
What you should do is something like this: import msgpack4nim import strutils import typetraits type MsgKind = enum MsgAlpha, MsgBeta Msg = object id: int case kind: MsgKind of MsgAlpha: x, y: int url: string of MsgBeta: resource: string # ... const info = { MsgAlpha: (id: 1), MsgBeta: (id: 2), # ... } proc serialize(msg: Msg) = var msgcopy = msg msgcopy.id = info[msg.kind].id # Too bad! echo msgcopy.pack.stringify serialize Msg(kind: MsgAlpha, x: 10, y: 30, url: "http://foo.bar") serialize Msg(kind: MsgBeta, resource: "GLES2") Run