Title: Typecast string to string literal · Issue #12879 · microsoft/TypeScript · GitHub
Open Graph Title: Typecast string to string literal · Issue #12879 · microsoft/TypeScript
X Title: Typecast string to string literal · Issue #12879 · microsoft/TypeScript
Description: TypeScript Version: 2.1.4 Code // in 2.1.4 iShouldBeStringLiteral is now a string let iShouldBeStringLiteral = type('This is a string') export function type
Open Graph Description: TypeScript Version: 2.1.4 Code // in 2.1.4 iShouldBeStringLiteral is now a string let iShouldBeStringLiteral = type('This is a string') export function type
X Description: TypeScript Version: 2.1.4 Code // in 2.1.4 iShouldBeStringLiteral is now a string let iShouldBeStringLiteral = type('This is a string') export function type<T>(label: T | ''):...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12879
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Typecast string to string literal","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n**TypeScript Version:** 2.1.4\r\n\r\n**Code**\r\n\r\n```ts\r\n// in 2.1.4 iShouldBeStringLiteral is now a string\r\nlet iShouldBeStringLiteral = type('This is a string')\r\nexport function type\u003cT>(label: T | ''): T {\r\n return \u003cT>label;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nBefore updating to typescript 2.1.4 the function transformed string to string literals with the same value\r\n**Actual behavior:**\r\nNow, even though the function returns a string literal type, assigning the return value to a variable / object property, will downcast it to string\r\n\r\n\r\n\r\nIn the second image, I would expect `x` to be of type `'String literal'`\r\n\r\n\r\n\r\nThis is especially in redux like scenarions, where you have to switch based on a constant and need the exhaustive checking in order to get type safety inside every case branch\r\n\r\nedit: I know the solution is a bit hackish, but it helps a lot. If there is any other way of doing this, I'm more than open to suggestions\r\n","author":{"url":"https://github.com/stochris","@type":"Person","name":"stochris"},"datePublished":"2016-12-13T12:21:35Z","url":"https://github.com/microsoft/TypeScript/issues/12879"}
| 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:45bd1b5c-6f16-95db-79ff-df5fc89be4a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E064:175A3:10BF8C:165116:6AFBDD7D |
| html-safe-nonce | c0353a0d80f7b2086af75902ea93eb94295011c93b58c348319e4904e867f9b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDY0OjE3NUEzOjEwQkY4QzoxNjUxMTY6NkFGQkREN0QiLCJ2aXNpdG9yX2lkIjoiODU1NDc4MjgzNjY2MTg1NTk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fb266b52b74cc2570f6c9ba51b028fd39a3dfe011d4c6db706fe950b797178ec |
| hovercard-subject-tag | issue:195239234 |
| 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/12879/issue_layout |
| twitter:image | https://opengraph.githubassets.com/46e76f28cb8fbf090f1e9289f04f4ca746dc8e9ea85490fc99a95d07ac1d8fb9/microsoft/TypeScript/issues/12879 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/46e76f28cb8fbf090f1e9289f04f4ca746dc8e9ea85490fc99a95d07ac1d8fb9/microsoft/TypeScript/issues/12879 |
| og:image:alt | TypeScript Version: 2.1.4 Code // in 2.1.4 iShouldBeStringLiteral is now a string let iShouldBeStringLiteral = type('This is a string') export function type |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stochris |
| hostname | github.com |
| expected-hostname | github.com |
| None | 744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec |
| 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 | df859c48a4c8b4c0009c19bb4e82101aacb4b998 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width