Title: negating type constraints · Issue #7993 · microsoft/TypeScript · GitHub
Open Graph Title: negating type constraints · Issue #7993 · microsoft/TypeScript
X Title: negating type constraints · Issue #7993 · microsoft/TypeScript
Description: Sometimes it's useful to put a limit on what a type parameter can be. In a way it is a counterpart of the extends constraint. Problem Consider an example, a classic function that takes whatever and returns void: function ignore(value:...
Open Graph Description: Sometimes it's useful to put a limit on what a type parameter can be. In a way it is a counterpart of the extends constraint. Problem Consider an example, a classic function that takes whatever and...
X Description: Sometimes it's useful to put a limit on what a type parameter can be. In a way it is a counterpart of the extends constraint. Problem Consider an example, a classic function that takes whatever...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7993
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"negating type constraints","articleBody":"Sometimes it's useful to put a limit on what a type parameter can be. In a way it is a counterpart of the `extends` constraint.\n### Problem\n\nConsider an example, a [classic function](https://msdn.microsoft.com/en-us/library/ee340357.aspx) that takes whatever and returns void:\n\n```\nfunction ignore\u003ca>(value: a) : void {};\n```\n\nHowever we must not apply this function to Promises, because it might get us a temporal leak if we do.\n\n```\nfunction readFileAsync(): Promise\u003cstring>;\nignore(readFileAsync()); // \u003c-- untracked promise, temporal leak\n```\n\nUnfortunately it is way too easy to get into a situation when a promise is passed to that function unintentionally as a result of refactoring:\n\n```\n// before\nfunction readFileSync(): string;\nignore(readFileSync()); // typechecks, works as intended, no problem\n\n// after refactoring\nfunction readFileAsync(): Promise\u003cstring>; // \u003c-- went async here\nignore(readFileAsync()); // typechecks, unintended temporal leak, big problem\n```\n### Solution\n\nThe situation above could have been avoided if TypeScript allowed negating constraints:\n\n```\nfunction ignore\u003ca unlike Promise\u003cany>>(value: a): void {} // \u003c-- hypothetical syntax\n```\n","author":{"url":"https://github.com/zpdDG4gta8XKpMCd","@type":"Person","name":"zpdDG4gta8XKpMCd"},"datePublished":"2016-04-10T11:10:20Z","url":"https://github.com/microsoft/TypeScript/issues/7993"}
| 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:31848e98-f0da-6feb-8e14-bed1a75803cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B30:1CEA6F:3AAB0E:4F33B6:6B00C6DE |
| html-safe-nonce | 7d7a12fe3ed766361ba8b278fcbfd6e219a21eff2edaed7b7805d419899d7c5e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjMwOjFDRUE2RjozQUFCMEU6NEYzM0I2OjZCMDBDNkRFIiwidmlzaXRvcl9pZCI6IjQ2NTcyODM1NzQ4ODAzMjMyOTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d990b9afd6315dbd098ba358bd4b556e362605f0e7f3f8a0ecd72ae371bdbf93 |
| hovercard-subject-tag | issue:147214866 |
| 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/7993/issue_layout |
| twitter:image | https://opengraph.githubassets.com/587babf8e2056cf0e75e157ddc9da4fcc52dbb6192b684b580c2d0b257b0f2ab/microsoft/TypeScript/issues/7993 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/587babf8e2056cf0e75e157ddc9da4fcc52dbb6192b684b580c2d0b257b0f2ab/microsoft/TypeScript/issues/7993 |
| og:image:alt | Sometimes it's useful to put a limit on what a type parameter can be. In a way it is a counterpart of the extends constraint. Problem Consider an example, a classic function that takes whatever and... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zpdDG4gta8XKpMCd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width