Title: Using special decorators for assertions and constraints · Issue #60093 · microsoft/TypeScript · GitHub
Open Graph Title: Using special decorators for assertions and constraints · Issue #60093 · microsoft/TypeScript
X Title: Using special decorators for assertions and constraints · Issue #60093 · microsoft/TypeScript
Description: 🔍 Search Terms typescript, inference, decorators, assertions, constraints ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime behavior of existing JavaScript co...
Open Graph Description: 🔍 Search Terms typescript, inference, decorators, assertions, constraints ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the ru...
X Description: 🔍 Search Terms typescript, inference, decorators, assertions, constraints ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't chang...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/60093
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using special decorators for assertions and constraints","articleBody":"### 🔍 Search Terms\r\n\r\ntypescript, inference, decorators, assertions, constraints\r\n\r\n### ✅ Viability Checklist\r\n\r\n- [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n- [X] This wouldn't change the runtime behavior of existing JavaScript code\r\n- [X] This could be implemented without emitting different JS based on the types of the expressions\r\n- [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\r\n- [X] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types\r\n- [X] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals\r\n\r\n### ⭐ Suggestion\r\n\r\nI would like to request a feature involving the use of one or more special decorators for providing even more information about types, functions, and properties.\r\n\r\n### 📃 Motivating Example\r\n\r\n```typescript\r\n@constraint((obj: Foo) => { assert(obj.x > obj.y) })\r\n@constraint((obj: Foo) => { assert(obj.y >= 0) })\r\n@constraint((obj: Foo) => { assert(obj.x >= 0) })\r\nclass Foo\r\n{\r\n x: number;\r\n y: number;\r\n}\r\n\r\n@constraint((obj: ExtendsFoo) => { assert(obj.z >= 0) })\r\nclass ExtendsFoo extends Foo\r\n{\r\n z: number;\r\n}\r\n```\r\n\r\n### 💻 Use Cases\r\n\r\n1. What do you want to use this for? Even more granular expressiveness about types. functions, and properties would be useful.\r\n\r\n2. What shortcomings exist with current approaches? With one or more special decorators, developers could express many more useful assertions and constraints.\r\n\r\n3. What workarounds are you using in the meantime? Workarounds are situation-dependent.","author":{"url":"https://github.com/AdamSobieski","@type":"Person","name":"AdamSobieski"},"datePublished":"2024-09-29T05:31:07Z","url":"https://github.com/microsoft/TypeScript/issues/60093"}
| 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:eb2b692e-5be3-8dca-949d-5f38772feaa4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8214:237673:BD04C1:FDBA4F:6B00F8C2 |
| html-safe-nonce | 8a5129a1dcb0a62361d7e897e2989ff2b58476f5ead59badf6ef4b57a90842db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjE0OjIzNzY3MzpCRDA0QzE6RkRCQTRGOjZCMDBGOEMyIiwidmlzaXRvcl9pZCI6IjYzMzAyOTc3MTQ2MzAyNjA5MzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c23c777e2c4f0a749db2d82dd0da8aa0a4ecb145bbf32a7dceb9d64ca1896d22 |
| hovercard-subject-tag | issue:2554715818 |
| 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/60093/issue_layout |
| twitter:image | https://opengraph.githubassets.com/58a9eea315b9495aa6d3dc7acb9e809df380e8d0e75f077a3277b7dd50fdf089/microsoft/TypeScript/issues/60093 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/58a9eea315b9495aa6d3dc7acb9e809df380e8d0e75f077a3277b7dd50fdf089/microsoft/TypeScript/issues/60093 |
| og:image:alt | 🔍 Search Terms typescript, inference, decorators, assertions, constraints ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the ru... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AdamSobieski |
| 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