Title: Type guard function does not work for string literal types · Issue #7441 · microsoft/TypeScript · GitHub
Open Graph Title: Type guard function does not work for string literal types · Issue #7441 · microsoft/TypeScript
X Title: Type guard function does not work for string literal types · Issue #7441 · microsoft/TypeScript
Description: TypeScript Version: 1.8.2 Code type Click = 'click'; function isClick(event: string): event is Click { return event === 'click'; } function validateClickEvent(event: string): Click { if (isClick(event)) { return event; // this line raise...
Open Graph Description: TypeScript Version: 1.8.2 Code type Click = 'click'; function isClick(event: string): event is Click { return event === 'click'; } function validateClickEvent(event: string): Click { if (isClick(ev...
X Description: TypeScript Version: 1.8.2 Code type Click = 'click'; function isClick(event: string): event is Click { return event === 'click'; } function validateClickEvent(event: string): Click ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7441
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type guard function does not work for string literal types","articleBody":"\u003c!--\nThank you for contributing to TypeScript! Please review this checklist\n before submitting your issue.\n[x] Many common issues and suggestions are addressed in the FAQ\n https://github.com/Microsoft/TypeScript/wiki/FAQ\n[x] Search for duplicates before logging new issues\n https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue\n[x] Questions are best asked and answered at Stack Overflow\n http://stackoverflow.com/questions/tagged/typescript\n\nFor bug reports, please include the information below.\n__________________________________________________________ -->\n\n**TypeScript Version:** \n\n1.8.2\n\n**Code**\n\n``` ts\ntype Click = 'click';\n\nfunction isClick(event: string): event is Click {\n return event === 'click';\n}\n\nfunction validateClickEvent(event: string): Click {\n if (isClick(event)) {\n return event; // this line raises a compilation error: Type 'string' is not assignable to type '\"click\"'\n }\n throw new Error('not click');\n}\n\ntype Creature = {};\ntype Animal = {} & Creature;\n\nfunction isAnimal(creature: Creature): creature is Animal {\n return true;\n}\n\nfunction validateAnimalCreature(creature: Creature): Animal {\n if (isAnimal(creature)) {\n return creature; // this line does not raise any compilation error\n }\n throw new Error('not animal');\n}\n\n```\n\n**Expected behavior:**\n\nCan apply type guard to string literal types.\n\n**Actual behavior:** \n\nCannot apply type guard to string literal types.\n","author":{"url":"https://github.com/kimamula","@type":"Person","name":"kimamula"},"datePublished":"2016-03-09T07:07:13Z","url":"https://github.com/microsoft/TypeScript/issues/7441"}
| 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:ec181649-7578-de4b-b1ee-8087b912c7a7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB8A:3B90C1:5730AC:7543C4:6AFBF203 |
| html-safe-nonce | dea5f202bef04517b037e71e0bd0facc3bff39f4b26ab8448b879d6fa61155e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjhBOjNCOTBDMTo1NzMwQUM6NzU0M0M0OjZBRkJGMjAzIiwidmlzaXRvcl9pZCI6IjY2MDA0OTE5NDI1NTc3NzQzMzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 80e25b2762445103d5f65cc4f0031715f1148a6621524e62df17ffb4363ed7f9 |
| hovercard-subject-tag | issue:139493980 |
| 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/7441/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab8b5a7a6d6908165cd1e6fdb1450cc61ac77c40da80928a50c326b6330737fd/microsoft/TypeScript/issues/7441 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab8b5a7a6d6908165cd1e6fdb1450cc61ac77c40da80928a50c326b6330737fd/microsoft/TypeScript/issues/7441 |
| og:image:alt | TypeScript Version: 1.8.2 Code type Click = 'click'; function isClick(event: string): event is Click { return event === 'click'; } function validateClickEvent(event: string): Click { if (isClick(ev... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kimamula |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width