Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Available decorator arguments:
- * - number
- * - string
- * - object
- * - boolean
- * - undefined
- * - null
- * - function
- */
- exports.typeDec = function typeDec(decoratorArgs) {
- return function (target, name, descriptor) {
- const fn = descriptor.value;
- const newFn = function(...args) {
- if (args[0] === undefined) return;
- fn.apply(target, arguments);
- args = args.map(arr => arr);
- for (let i = 0; i < args.length; i++) {
- if (decoratorArgs[i] !== typeof args[i]) {
- console.warn(`TypeException in func ${name.toString()} expected type ${decoratorArgs[i]} received
- ${args[i]} with type ${typeof args[i]}`)
- }
- }
- }
- descriptor.value = newFn;
- return descriptor.value;
- }
- }
Add Comment
Please, Sign In to add comment