Title: New keyword: alias, a local type definition replacer · Issue #40780 · microsoft/TypeScript · GitHub
Open Graph Title: New keyword: alias, a local type definition replacer · Issue #40780 · microsoft/TypeScript
X Title: New keyword: alias, a local type definition replacer · Issue #40780 · microsoft/TypeScript
Description: Search Terms alias, type alias Suggestion When writing a complex type, often the code becomes a "type spaghetti", being hard and time consuming to identify what all those AAA
Open Graph Description: Search Terms alias, type alias Suggestion When writing a complex type, often the code becomes a "type spaghetti", being hard and time consuming to identify what all those AAA X Description: Search Terms alias, type alias Suggestion When writing a complex type, often the code becomes a "type spaghetti", being hard and time consuming to identify what all those AAA<BBBBB[] e...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/40780
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"New keyword: alias, a local type definition replacer","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ, especially the \"Common Feature Requests\" section: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\n-->\r\n\r\n## Search Terms\r\nalias, type alias\r\n\r\n\u003c!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->\r\n\r\n## Suggestion\r\n\r\nWhen writing a complex type, often the code becomes a \"type spaghetti\", being hard and time consuming to identify what all those AAA\u003cBBBBB[] extends ? BB: >... and it is even worse when we have to use a same lengthy type that is used in more than once place inside a generic type.\r\n\r\nMy suggestion is to create a new Typescript keyword, the `alias` or something like that, that would work like a \"local const\" for types or a simple type replacer. Like C macros for types.\r\n\r\n\u003c!-- A summary of what you'd like to see added or changed -->\r\n\r\n## Use Cases\r\n\r\nWould reduce code size and the time to understand the code, and improve code readability and comprehension.\r\n\r\nIt is possible to create auxiliary types, but being a type necessarily generic, we still have to pass the generic types for every time we call them.\r\n \r\n\u003c!--\r\nWhat do you want to use this for?\r\nWhat shortcomings exist with current approaches?\r\n-->\r\n\r\n## Examples\r\n\r\n```ts\r\ntype MyType\u003cChildrenOrType extends ... , Key extends ... , Extra extends ... > = ...\u003c...\u003c {\r\n a: AnotherType\u003cChildrenOrType, Key, Extra>;\r\n b: (data: AnotherType\u003cChildrenOrType, Key, Extra>): string;\r\n c: (data: number) => AnotherType\u003cChildrenOrType, Key, Extra>\r\n}>...>...\r\n```\r\nEven reducing the generic types to the famous T,Q,U,P etc, which reduces the code length but also makes it more hard to understand what each type is for, still isn't good to use \u003cT, Q, P, X> for each time you want to mention the generic types.\r\n```ts\r\ntype MyType\u003cCT extends ... , K extends ... , E extends ... > = ...\u003c...\u003c {\r\n a: AnotherType\u003cCT, K, E>;\r\n b: (data: AnotherType\u003cCT, K, E>): string;\r\n c: (data: number) => AnotherType\u003cCT, K, E>;\r\n}>...>...\r\n```\r\nHere is my suggestion:\r\n\r\n```ts\r\ntype MyType\u003cChildrenOrType extends ... , Key extends ... , Extra extends ... > = ...\u003c...\u003c {\r\n alias AliasAnotherType = AnotherType\u003cChildrenOrType, Key, Extra>\r\n a: AliasAnotherType;\r\n b: (data: AliasAnotherType): string;\r\n c: (data: number) => AliasAnotherType\r\n}>...>...\r\n```\r\nOr using letters for types\r\n```ts\r\ntype MyType\u003cCT extends ... , K extends ... , E extends ... > = ...\u003c...\u003c {\r\n alias AliasAnotherType = AnotherType\u003cCT, K, E>\r\n a: AliasAnotherType;\r\n b: (data: AliasAnotherType): string;\r\n c: (data: number) => AliasAnotherType\r\n}>...>...\r\n```\r\nIt would also fit well in recursive types.\r\n\r\n\u003c!-- Show how this would be used and what the behavior would be -->\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n\r\nMaybe it could accept generics too.\r\n\r\nA thing to think about this is: what should be the scope of those alias? Should they work/apply anywhere inside the type definition? Local inside (), {}, \u003c>?","author":{"url":"https://github.com/ftzi","@type":"Person","name":"ftzi"},"datePublished":"2020-09-25T21:38:33Z","url":"https://github.com/microsoft/TypeScript/issues/40780"}
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:57a976d5-fd01-d085-25c6-68d6ad078c3c current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id DF02:2A5566:F098D4:13C16BE:6B01D191 html-safe-nonce 39b4c30e2ca78681da7330ded8dbd73da0b7a0c2c446c5b32fc7a71e9dd07b49 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjAyOjJBNTU2NjpGMDk4RDQ6MTNDMTZCRTo2QjAxRDE5MSIsInZpc2l0b3JfaWQiOiIyMTQxNzYwNjYxNzA3OTM2MTQ1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= visitor-hmac 7d854cefc3cfe867f0324c98b2ed8eb5820c09b64c078768b7fad7fe51ce007d hovercard-subject-tag issue:709298356 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/40780/issue_layout twitter:image https://opengraph.githubassets.com/798749d0ae6fef98468d7628e1fa4cab41762801efd82c58bc2b0fb31311f2c1/microsoft/TypeScript/issues/40780 twitter:card summary_large_image og:image https://opengraph.githubassets.com/798749d0ae6fef98468d7628e1fa4cab41762801efd82c58bc2b0fb31311f2c1/microsoft/TypeScript/issues/40780 og:image:alt Search Terms alias, type alias Suggestion When writing a complex type, often the code becomes a "type spaghetti", being hard and time consuming to identify what all those AAA og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username ftzi 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
URLs of crawlers that visited me.