In this direction, to make it work, you have to do a cast: proc newElementA(): ElementA = cast[ElementA](newElement("A")) Run
Another way consists to create a proc _initElement_ in _lib_ : proc initElement*(elem: Element, id: string) = elem.id = id Run then to define _newElementA_ this way: proc newElementA(): ElementA = new result result.initElement("A") Run