{"id":13565458,"url":"https://github.com/David-Kunz/derive-type","last_synced_at":"2025-04-03T22:31:29.872Z","repository":{"id":56901198,"uuid":"526859959","full_name":"David-Kunz/derive-type","owner":"David-Kunz","description":"Derive types dynamically by running tests to capture value combinations","archived":false,"fork":false,"pushed_at":"2022-09-04T11:06:55.000Z","size":87,"stargazers_count":46,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-24T04:11:59.126Z","etag":null,"topics":["javascript","type-generation","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/David-Kunz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-20T07:43:42.000Z","updated_at":"2024-03-01T17:32:21.000Z","dependencies_parsed_at":"2022-08-20T18:20:53.144Z","dependency_job_id":null,"html_url":"https://github.com/David-Kunz/derive-type","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/David-Kunz%2Fderive-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/David-Kunz%2Fderive-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/David-Kunz%2Fderive-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/David-Kunz%2Fderive-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/David-Kunz","download_url":"https://codeload.github.com/David-Kunz/derive-type/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247090244,"owners_count":20881938,"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":["javascript","type-generation","typescript"],"created_at":"2024-08-01T13:01:47.306Z","updated_at":"2025-04-03T22:31:29.457Z","avatar_url":"https://github.com/David-Kunz.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Derive Type\n\nGenerate [TypeScript](https://www.typescriptlang.org/) type definitions based on function invocations and embed them as [JSDoc](https://jsdoc.app/) comments in your JavaScript code.\n\n## Demo\n\nhttps://user-images.githubusercontent.com/1009936/188266007-269ee08a-392c-4dfe-af80-444059ebba39.mov\n\n## Installation\n\n```bash\nnpm i -D derive-type\n```\n\n## Simple Example\n\nOriginal source code:\n\n```js\n// main.js\n\nfunction myFunction(x, y) {\n  console.log(x, y)\n}\n\nmyFunction(1, 2)\n```\n\nAdd this function call at the top of your function body:\n\n```js\n// main.js\n\nfunction myFunction(x, y) {\n  require('derive-type')(x, y) // \u003c- ADD THIS\n  console.log(x, y)\n}\n\nmyFunction(1, 2)\n```\n\nThen invoke the binary with the code to trigger the function invocations:\n\n```bash\nnpx derive-type node main.js\n```\n\nThis will generate the [TypeScript](https://www.typescriptlang.org/) definition, insert the [JSDoc](https://jsdoc.app/) snippet\nand remove the call to `derive-type`:\n\n```js\n// main.js\n\n/** @type { import(\"/var/folders/ls/xxxx/T/derive-type-gen/KC9Vc2Vycy9kMDY1MDIzL3Byb2plY3RzL0Rldk9uRHV0eS9kZXJpdmUtdHlwZS10ZXN0L3Rlc3QuanM6NDoyNSk=\").GEN } Generated */\nfunction myFunction(x, y) {\n  // now you know that `x` and `y` are of type `number`\n  console.log(x, y)\n}\n\nmyFunction(1, 2)\n```\n\n## Notes\n\n- The function invocations don't need to be in the same file, usually they are based on tests:\n  ```bash\n  npx derive-type npm test\n  ```\n- The generated types are based on the merged input of all function invocations.\n- The function definition must begin in a new line.\n- You can also install `derive-type` globally, then you must use the path of your global package, e.g. `require(\"/usr/local/lib/node_modules/derive-type/\")`.\n- The generated types are located in `os.tmpdir()` (changeable via `DERIVE_TYPE_FOLDER`).\n- The generated types are deleted after 5 days (changeable via `DERIVE_TYPE_MAX_AGE_DAYS`).\n- Debugging output can be enabled by setting `DERIVE_TYPE_DEBUG` to true.\n- You can find some example type generations [in the test file](https://github.com/David-Kunz/derive-type/blob/main/tests/derive.test.js).\n\n## Introduction Video\n\n[![](https://img.youtube.com/vi/gdz_X0b5SnM/0.jpg)](https://youtu.be/gdz_X0b5SnM\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavid-Kunz%2Fderive-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDavid-Kunz%2Fderive-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavid-Kunz%2Fderive-type/lists"}