{"id":23510824,"url":"https://github.com/danielkov/decorators-parameter-typecheck","last_synced_at":"2025-05-13T17:17:19.046Z","repository":{"id":98242007,"uuid":"78984895","full_name":"danielkov/decorators-parameter-typecheck","owner":"danielkov","description":"ES7 or ESNext Decorator for TypeScript-like type checking on class methods.","archived":false,"fork":false,"pushed_at":"2017-01-15T02:00:33.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T11:49:41.058Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielkov.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-15T01:38:20.000Z","updated_at":"2017-01-15T02:00:34.000Z","dependencies_parsed_at":"2023-04-21T02:32:30.118Z","dependency_job_id":null,"html_url":"https://github.com/danielkov/decorators-parameter-typecheck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielkov%2Fdecorators-parameter-typecheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielkov%2Fdecorators-parameter-typecheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielkov%2Fdecorators-parameter-typecheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielkov%2Fdecorators-parameter-typecheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielkov","download_url":"https://codeload.github.com/danielkov/decorators-parameter-typecheck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990503,"owners_count":21995776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-25T12:12:27.240Z","updated_at":"2025-05-13T17:17:19.020Z","avatar_url":"https://github.com/danielkov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Read Me!\n\nDecorators are not even in the cut for ES7, which means if you want to use this extremely convenient little library, you'll have to compile it with [Babel](http://babeljs.io/), using the following plugin: [babel-plugin-transform-decorators-legacy](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy).\n\n# How to use\n\nAs I was looking for an easier way to add type checking to my dependencies of other modules, I realised that most of the time I was simply writing the same things over and over. As awesome programmers, we should keep our code DRY and so this is what I came up with. Hope you'll like it and feel free to contribute to it.\n\nBasic example:\n\n```js\nimport * as typecheck from 'decorators-typecheck'\n// same as const typecheck = require('decorators-typecheck'); You'll need to transpile it with Babel even for Node JS anyway.\n\nclass MyClass {\n  constructor(...args) {\n    this.data = args\n  }\n\n  @typecheck('string')\n  sayHello (name) {\n    console.log(`Hello, ${name}!`)\n  }\n\n  @typecheck('object', 'array') // notice that this module knows the difference between an array and other objects.\n  compare (obj, arr) {\n    for (item of obj) {\n      if (arr.includes(obj[item])) {\n        console.log(`We've got a match: ${obj[item]}!`)\n      }\n    }\n  }\n\n  @typecheck('any', 'any', 'optional') // if we want to make it so that typecheck skips some arguments, we can give it the 'any' or 'optional' argument. They do the same thing, but your collegue may thank you for using both.\n  lastFunction (any, sortOf, arg) {\n    \n  }\n}\n\nlet myClass = new myClass()\n\nmyClass.sayHello('Daniel') // \u003e Hello, Daniel!\n\nmyClass.sayHello({name: 'Daniel'}) // \u003e Uncaught TypeError: Argument 0 should be of type string. Specified type: object.\n\n// The following will not run after error. So let's assume this is another scenario...\n\nmyClass.compare({ one: 'something', two: 'otherthing' }, ['something', 'somethingElse']) // \u003e We've got a match: something!\n\nmyClass.compare(['something', 'somethingElse'], { one: 'something', two: 'otherthing' }) // \u003e Uncaught TypeError: Argument 0 should be of type object. Specified type: array.\n```\n\n# Learn More about Decorators\n\nTo learn more about decorators follow [this link.](https://github.com/wycats/javascript-decorators)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielkov%2Fdecorators-parameter-typecheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielkov%2Fdecorators-parameter-typecheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielkov%2Fdecorators-parameter-typecheck/lists"}