type.js refactor