Title: Allow inline type predicates · Issue #6474 · microsoft/TypeScript · GitHub
Open Graph Title: Allow inline type predicates · Issue #6474 · microsoft/TypeScript
X Title: Allow inline type predicates · Issue #6474 · microsoft/TypeScript
Description: From #5731 if (
Open Graph Description: From #5731 if (
X Description: From #5731 if (<foo is Element>(foo.nodeType === 1)) { // Assume foo is Element here } A proposal from Nathan Shively-Sanders (@sandersn): #5731 (comment) Type Predicate Expressions A type pr...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6474
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow inline type predicates","articleBody":"From #5731 \n\n``` typescript\nif (\u003cfoo is Element>(foo.nodeType === 1)) { \n // Assume foo is Element here\n}\n```\n\nA proposal from @sandersn: https://github.com/Microsoft/TypeScript/issues/5731#issuecomment-162586789\n\n> ## Type Predicate Expressions\n> \n> A type predicate expression allows you to narrow a union type with a single expression. The syntax is \n> \n> > `\u003c`_variable_ `is` _type_`>` _boolean-expression_\n> \n> When the expression is used in a conditional context, the true branch of the conditional narrows variable to type, while the false branch narrows variable by removing type. \n> \n> The type predicate expression is of type Boolean, with apparent type of type predicate. The right hand side must be an expression of type Boolean. The left hand side's variable must be a name bound in the current scope. The left hand side's type must be a name bound in the current scope. \n> ### Open questions\n> 1. How does variable capture work? Can a type predicate expression be returned from a function and used to narrow a variable that's no longer in scope? This could be defined to cause an error, but that restriction is neither obvious nor easy to use.\n> 2. Why reuse the type assertion syntax? The type of the right expression is checked to be Boolean, unlike assertions, and the resulting type is still Boolean, also unlike assertions. \n","author":{"url":"https://github.com/saschanaz","@type":"Person","name":"saschanaz"},"datePublished":"2016-01-14T04:35:43Z","url":"https://github.com/microsoft/TypeScript/issues/6474"}
| 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:147df859-f09a-0bc3-57dd-fef8c396b79f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5C8:33444D:B0D1C9:EC9A44:6B00F200 |
| html-safe-nonce | 809afc5173577733d3b34a3520b3cbb2ca5501248db63a20827c54b67b05936b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUM4OjMzNDQ0RDpCMEQxQzk6RUM5QTQ0OjZCMDBGMjAwIiwidmlzaXRvcl9pZCI6Ijc1NTgzNzUxMTI0ODgwNTUyOTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 09d086bf02c7e2702fe3ed69dc10a2c397ae792643791dec0b6750faf0c2f5d2 |
| hovercard-subject-tag | issue:126575435 |
| 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/6474/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8da4fca7c07c3fbedec1380739eee47dc264280b4e41096a468318467e7e6fc2/microsoft/TypeScript/issues/6474 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8da4fca7c07c3fbedec1380739eee47dc264280b4e41096a468318467e7e6fc2/microsoft/TypeScript/issues/6474 |
| og:image:alt | From #5731 if ( |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | saschanaz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width