{"id":13455790,"url":"https://github.com/rikukissa/typehole","last_synced_at":"2025-05-15T17:06:17.255Z","repository":{"id":47264932,"uuid":"360254195","full_name":"rikukissa/typehole","owner":"rikukissa","description":"TypeScript development tool for Visual Studio Code that helps you automate creating the initial static typing for runtime values","archived":false,"fork":false,"pushed_at":"2023-03-14T18:45:53.000Z","size":7415,"stargazers_count":1056,"open_issues_count":10,"forks_count":13,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-14T09:53:49.043Z","etag":null,"topics":["ast","extension","typescript","vscode"],"latest_commit_sha":null,"homepage":"https://marketplace.visualstudio.com/items?itemName=rikurouvila.typehole","language":"TypeScript","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/rikukissa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-04-21T17:33:34.000Z","updated_at":"2025-05-12T18:41:21.000Z","dependencies_parsed_at":"2024-01-13T17:48:07.400Z","dependency_job_id":"782835ae-159b-4485-9298-eee33064811d","html_url":"https://github.com/rikukissa/typehole","commit_stats":{"total_commits":126,"total_committers":3,"mean_commits":42.0,"dds":0.03968253968253965,"last_synced_commit":"96bf313bb800e81b7fa887ba1e1572ecc9d6d820"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rikukissa%2Ftypehole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rikukissa%2Ftypehole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rikukissa%2Ftypehole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rikukissa%2Ftypehole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rikukissa","download_url":"https://codeload.github.com/rikukissa/typehole/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"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":["ast","extension","typescript","vscode"],"created_at":"2024-07-31T08:01:11.115Z","updated_at":"2025-05-15T17:06:12.246Z","avatar_url":"https://github.com/rikukissa.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","vscode"],"sub_categories":[],"readme":"# Typeh\u003cimg src=\"./images/title-logo.png\" align=\"top\" width=\"24px\"\u003ele\n\nAutomatically generate TypeScript types and interfaces for all serializable runtime values.\n\n[English](#) | [简体中文](./docs/zh.md)\n\nTypehole is a TypeScript development tool for Visual Studio Code that automates creating static typing by bridging runtime values from your Node.js or browser application to your code editor. It's useful when you need types for an API response or want to figure out types for values coming from a JS module.\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n![file](./images/demo.gif)\n\n## Installation\n\nInstall the [Visual Studio Code - extension](https://marketplace.visualstudio.com/items?itemName=rikurouvila.typehole). No additional build tooling or compiler plugins are needed.\n\n## How does it work?\n\n1. Find an `any` / `unknown` value you need an interface for\n\n```typescript\nconst response = await axios.get(\"https://reddit.com/r/typescript.json\");\nconst data /* any */ = response.data;\n```\n\n2. Place the value inside a typehole by selecting an expression and opening the **Quick Fix** menu by pressing ⌘ + . (macOS) or ctrl + . (Windows) and selecting **Add a typehole**.\n\n```typescript\ntype RedditResponse = any; // Type placeholder inserted by the extension\nconst response = await axios.get(\"https://reddit.com/r/typescript.json\");\n\nconst data: RedditResponse = typehole.t(response.data);\n```\n\n3. Run your code either in a browser or in Node.js. Typehole runtime captures the value and sends it back to your code editor. The VSCode extension records the captured value, turns all the values from that typehole into an interface and inserts it into the same module.\n\n```typescript\ninterface RedditResponse {\n  /* ✨ Actual fields and types are automatically generated ✨ */\n}\n\nconst response = await axios.get(\"https://reddit.com/r/typescript.json\");\nconst data: RedditResponse = typehole.t(response.data);\n```\n\n4. Remove the typehole, and you're done. Typeholes are meant to be development-time only, so you shouldn't commit them. Typehole provides you with 2 [commands](#commands) for easy removal of typeholes.\n\n```typescript\ninterface RedditResponse {\n  /* ✨ Actual fields and types are automatically generated ✨ */\n}\n\nconst response = await axios.get(\"https://reddit.com/r/typescript.json\");\nconst data: RedditResponse = response.data;\n```\n\nThis plugin is still very experimental, so please expect and report issues.\n\n## Features\n\n- Generate TypeScript types from runtime values\n- Run the code many times with different values thus augmenting your types\u003cbr/\u003e\u003cbr/\u003e\u003cimg width=\"500\" src=\"./images/samples.gif\" /\u003e\n\n- Wrap values automatically to typeholes with a code action\u003cbr/\u003e\u003cbr/\u003e\u003cimg width=\"500\" src=\"./images/code-action.png\" /\u003e\n\n### Values that can be automatically typed\n\nAll primitive values and values that are JSON serializable.\n\n- Booleans\n- Numbers\n- Strings\n- Arrays\n- Objects\n- null\n\nSo all values you can receive as an HTTP request payload can be turned into an interface.\n\nFrom 1.4.0 forward also Promises are supported. All other values (functions etc.) will be typed as `any`.\n\n## Commands\n\n![image](./images/commands.png)\n\n- Starting and stopping the server manually isn't necessary by default. The server starts once you add your first typehole.\n\n## Extension Settings\n\n| Setting                         | Type              | Default   | Description                                                                     |\n| ------------------------------- | ----------------- | --------- | ------------------------------------------------------------------------------- |\n| typehole.runtime.autoInstall    | boolean           | true      | Install Typehole runtime package automatically when the first typehole is added |\n| typehole.runtime.projectPath    | string            |           | Project directory where Typehole runtime should be installed                    |\n| typehole.runtime.packageManager | npm \\| yarn       | npm       | Package manager to be used when installing the runtime                          |\n| typehole.runtime.extensionPort  | number            | 17341     | HTTP port for HTTP extension to listen for incoming samples                     |\n| typehole.typeOrInterface        | interface \\| type | interface | Keyword to be used for generated types                                          |\n\n## Runtime\n\nTypehole runtime's job is to capture values in your code and to send them to the extension in a serialized format.\n\n```typescript\nimport typehole from \"typehole\";\n\n// -\u003e POST http://extension/samples {\"id\": \"t\", \"sample\": \"value\"}\ntypehole.t(\"value\");\n\n// -\u003e POST http://extension/samples {\"id\": \"t1\", \"sample\": 23423.432}\ntypehole.t1(23423.432);\n\n// -\u003e POST http://extension/samples {\"id\": \"t2\", \"sample\": {\"some\": \"value\"}}\ntypehole.t2({ some: \"value\" });\n```\n\nTypeholes are identified by the method name of your typehole call. Call `.t2()` would give the hole an id \"t2\". The ids are there, so the extension knows from where the value is coming from in the code.\n\nIn most cases, you should use unique keys for all holes. However, if you wish to record values from many holes into the same type, you might use the same id.\n\nIn some cases, the extension might not be running on the same host as your code, and you want to configure the address where the runtime sends the values. Node.js application running inside of a Docker container is one such case. In most cases, however, you do not need to configure anything.\n\n```typescript\nimport typehole, { configure } from \"typehole\";\n\nconfigure({\n  extensionHost: \"http://host.docker.internal:17341\",\n});\n```\n\n### Available runtime settings\n\n| Setting       | Type   | Default                | Description                                                 |\n| ------------- | ------ | ---------------------- | ----------------------------------------------------------- |\n| extensionHost | string | http://localhost:17341 | The address in which the extension HTTP listener is running |\n\n## Known Issues\n\n- Typehole server cannot be running in 2 VSCode editors at the same time as the server port is hard-coded to 17341\n\n## Release Notes\n\n## [1.8.0] - 2023-03-14\n\n### Added\n\n- Add native NodeJS ESM modules support [#24](https://github.com/rikukissa/typehole/pull/24)\n\n## [1.7.0] - 2021-07-08\n\n### Added\n\n- New option \"typehole.typeOrInterface\" added for using `type` keyword instead of `interface`. All thanks to @akafaneh 🎉\n\n## [1.6.3] - 2021-06-20\n\n### Fixed\n\n- Fixes code formatting generating broken / duplicate code\n\n## [1.6.2] - 2021-05-22\n\n### Fixed\n\n- Fixes null values marking fields as optional. `[{\"foo\": null}, {\"foo\": 2}]` now generates a type `{foo: null | number}[]` and not `{foo?: number}[]` like it used to. Should fix [#14](https://github.com/rikukissa/typehole/issues/14)\n\n## [1.6.1] - 2021-05-22\n\n### Fixed\n\n- Fix the automatic formatting in files where types are inserted\n\n## [1.6.0] - 2021-05-20\n\n### Added\n\n- Options for configuring both the extension server port and runtime host address. Addresses [#13](https://github.com/rikukissa/typehole/issues/13)\n\n## [1.5.1] - 2021-05-18\n\n### Fixed\n\n- Multiple typeholes can now exist with the same id. Each update from all of them updates all types attached to the holes. Useful, for example, when you want to have multiple typeholes update the same type.\n- No duplicated interfaces anymore when the generated top-level type is a `ParenthesizedType`\n- Interface not updating when it was in a different file than the typehole\n- Types not updating when some other file was focused in the editor\n- `typehole.tNaN` [issue](https://github.com/rikukissa/typehole/issues/7) when there have been typeholes with a non `t\u003cnumber\u003e` format\n\n## [1.5.0] - 2021-05-15\n\n### Added\n\n- Support for inferring Promises 👀\n\n### Fixed\n\n- Runtime now installed also on startup if there are typeholes in your code\n- No more duplicate AutoDiscoveredN types\n\n## [1.4.1] - 2021-05-09\n\n### Fixed\n\n- Unserializable diagnostic now shown only once per typehole. Previously the tooltip could have the same warning multiple times.\n\n- Server is now stopped once all typeholes are removed. Restarting the server now also works\n\n### Added\n\n## [1.4.0] - 2021-05-09\n\n### Added\n\n- Sample collection. Provide multiple different values to a typehole and the generated type gets refined based on them.\n\n## [1.3.0] - 2021-05-08\n\n### Added\n\n- Configuration options for project path, package manager and if runtime should be automatically installed\n\n## [1.1.0] - 2021-05-08\n\n### Added\n\n- Automatic PascalCase transformation for all generated interface and type alias names\n\n---\n\n**Enjoy!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frikukissa%2Ftypehole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frikukissa%2Ftypehole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frikukissa%2Ftypehole/lists"}