Title: Suggested refactoring: move function/type/class to new file · Issue #13859 · microsoft/TypeScript · GitHub
Open Graph Title: Suggested refactoring: move function/type/class to new file · Issue #13859 · microsoft/TypeScript
X Title: Suggested refactoring: move function/type/class to new file · Issue #13859 · microsoft/TypeScript
Description: I suggest adding a refactoring/code fix that helps with the task of moving a class/function/type or other top level declaration out of the current file and into another file, updating references as needed. Motivation Often when starting ...
Open Graph Description: I suggest adding a refactoring/code fix that helps with the task of moving a class/function/type or other top level declaration out of the current file and into another file, updating references as...
X Description: I suggest adding a refactoring/code fix that helps with the task of moving a class/function/type or other top level declaration out of the current file and into another file, updating references as...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/13859
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggested refactoring: move function/type/class to new file","articleBody":"I suggest adding a refactoring/code fix that helps with the task of moving a class/function/type or other top level declaration out of the current file and into another file, updating references as needed.\r\n\r\n**Motivation**\r\nOften when starting out with a new feature it makes sense to start to write code in a single file while working out the design. However, as soon as long method bodies start getting implemented or when code gets checked in to version control, it makes less sense and gets harder to work with and you want to move top level members into separate files.\r\n\r\nI've found CodeRush and ReSharper's \"Move Type to File\" tool (for VS/C#) very useful in this workflow and I miss it greatly when working with TypeScript/VS Code. \r\n\r\n**Example**\r\n\r\nbefore:\r\n```typescript\r\n// MyView.ts\r\n\r\nclass MyListItem { \r\n // ...\r\n} \r\n\r\nexport default class MyView {\r\n myItems: MyListItem[];\r\n // ...\r\n}\r\n```\r\n\r\nafter invoking \"Move declaration to file\" on MyListItem:\r\n```typescript\r\n// MyListItem.ts\r\nexport default class MyListItem { \r\n // ...\r\n} \r\n\r\n// MyView.ts\r\nimport MyListItem from \"./MyListItem\";\r\n\r\nexport default class MyView {\r\n myItems: MyListItem[];\r\n // ...\r\n}\r\n```\r\n\r\n**Design**\r\n- I suggest that this type of feature should require as little input as possible, ideally just be a single shortcut without dialogs, generating an appropriately named file.\r\n- It needs to take module configuration into consideration (i.e. should import/export be generated or not)\r\n- Should generate `.tsx` extension as appropriate, either based on the file it is invoked in or the contents of the code transferred. \r\n\r\nEdit: removed parenthesis after class names","author":{"url":"https://github.com/markusjohnsson","@type":"Person","name":"markusjohnsson"},"datePublished":"2017-02-03T08:37:40Z","url":"https://github.com/microsoft/TypeScript/issues/13859"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3148947d-f2d3-3c83-7599-a9671fc2d469 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D394:842EC:241575D:301BF71:6B019BC9 |
| html-safe-nonce | 8229c41962956de9ee35f67076b6955536a1879574f92b259d81265119350f75 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzk0Ojg0MkVDOjI0MTU3NUQ6MzAxQkY3MTo2QjAxOUJDOSIsInZpc2l0b3JfaWQiOiIzNjM0NzQ2MDAzMDkwOTM4ODI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e129adabfcf3bc4f48f0128f026cbad8d6db1c0814a77e7eac5bcaa7217d6142 |
| hovercard-subject-tag | issue:205099366 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/13859/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e6204498a83a4f5559deeaed3c86eb71d539ef30e7962577b4be8b5e7f99179/microsoft/TypeScript/issues/13859 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e6204498a83a4f5559deeaed3c86eb71d539ef30e7962577b4be8b5e7f99179/microsoft/TypeScript/issues/13859 |
| og:image:alt | I suggest adding a refactoring/code fix that helps with the task of moving a class/function/type or other top level declaration out of the current file and into another file, updating references as... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markusjohnsson |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width