Title: String literal type operators · Issue #12940 · microsoft/TypeScript · GitHub
Open Graph Title: String literal type operators · Issue #12940 · microsoft/TypeScript
X Title: String literal type operators · Issue #12940 · microsoft/TypeScript
Description: It would be useful if we could combine string literal types to create new types. For example suppose A and B extend string then: type AB = A + B; // strings formed from a member of A concatenated with a member of B. type Ax = A + string;...
Open Graph Description: It would be useful if we could combine string literal types to create new types. For example suppose A and B extend string then: type AB = A + B; // strings formed from a member of A concatenated w...
X Description: It would be useful if we could combine string literal types to create new types. For example suppose A and B extend string then: type AB = A + B; // strings formed from a member of A concatenated w...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12940
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"String literal type operators","articleBody":"It would be useful if we could combine string literal types to create new types. For example suppose `A` and `B` extend `string` then:\r\n\r\n```ts\r\ntype AB = A + B; // strings formed from a member of A concatenated with a member of B.\r\ntype Ax = A + string; // strings starting with a member of A\r\ntype xB = string + B; // strings ending with a member of B\r\n```\r\n\r\nThis would combine well with mapped types. For example suppose we want to specify an ordering of records of type `T` to some third-party module that requires SQL-like syntax. We could write:\r\n\r\n```ts\r\nfunction orderBy\u003cT>(records: Array\u003cT>, order: (keyof T) + ('' | ' ASC' | ' DESC')) {\r\n ...\r\n}\r\nlet records = [{x: 5}, {x: 2}, {x: 7}];\r\norderBy(records , 'x');\r\norderBy(records , 'x DESC');\r\n```\r\n\r\nMaybe some other forms would be useful:\r\n```ts\r\ntype notA = !A; // any string except for the members of A\r\ntype notAx = !A + string; // strings not starting with a member of A\r\ntype AxB = A + string + B; // equal to Ax & xB\r\ntype xAx = string + A + string; // strings containing a member of A\r\ntype A3 = A * 3; // A + A + A\r\n```\r\n\r\n","author":{"url":"https://github.com/zamb3zi","@type":"Person","name":"zamb3zi"},"datePublished":"2016-12-15T10:27:39Z","url":"https://github.com/microsoft/TypeScript/issues/12940"}
| 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:802dd0f4-035b-15ee-126a-d2391e4c7173 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B05A:F7C4C:BAEC05:FBC7F2:6B00F959 |
| html-safe-nonce | b5c963efa74dd92e237c25c7e06cf01afac5b6dedb45bd27e61aadd408d8a55f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDVBOkY3QzRDOkJBRUMwNTpGQkM3RjI6NkIwMEY5NTkiLCJ2aXNpdG9yX2lkIjoiNzM5NDUxNzkzOTczMjQxMjc2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4b1917462007f787d345e20b1f781bfb62c8bbdf6f74f57001226a814582db4b |
| hovercard-subject-tag | issue:195768771 |
| 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/12940/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f74eb80cb28f6fc86f3384fb11fb1e04ba806361348c57cc3b65a75052230ca5/microsoft/TypeScript/issues/12940 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f74eb80cb28f6fc86f3384fb11fb1e04ba806361348c57cc3b65a75052230ca5/microsoft/TypeScript/issues/12940 |
| og:image:alt | It would be useful if we could combine string literal types to create new types. For example suppose A and B extend string then: type AB = A + B; // strings formed from a member of A concatenated w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zamb3zi |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width