import { Item } from './elements' ; export interface ItemConstructor { ITEM_TYPE : string ; new ( ) : Item ; } const itemTypeRegistry = new Map < string , ItemConstructor > ( ) ; const restrictedPropNames = new Set < string > ( ) ; restrictedPropNames . add ( 'marktype' ) ; param itemType param ctor export function registerItemType ( ctor ) { itemTypeRegistry . set ( ctor . ITEM_TYPE , ctor ) ; } param itemType export function createItemType ( itemType , props = { } ) { if ( ! itemTypeRegistry . has ( itemType ) ) { throw new Error ( `item type ${ itemType } not found` ) ; } const ctor = itemTypeRegistry . get ( itemType ) ; if ( ctor === undefined ) { throw new Error ( `item type ${ itemType } constructor not valid` ) ; } const instance = new ctor ( ) ; Object . keys ( props ) . forEach ( propName => { if ( ! restrictedPropNames . has ( propName ) ) { instance [ propName ] = props [ propName ] ; } } ) ; return instance ; }