Added typecheck before setting defaultvalue since it is possible to change templatetype in metadata.