Title: Feature Request: strictier array and string using parenthesis modifiers · Issue #23617 · microsoft/TypeScript · GitHub
Open Graph Title: Feature Request: strictier array and string using parenthesis modifiers · Issue #23617 · microsoft/TypeScript
X Title: Feature Request: strictier array and string using parenthesis modifiers · Issue #23617 · microsoft/TypeScript
Description: TypeScript Version: 2.7.0-dev.201xxxxx Search Terms: string, array, length, modifier, strict Some strictly typed languages can catch string / array overflows on compile time against hard coded values, and might help catching some bugs ea...
Open Graph Description: TypeScript Version: 2.7.0-dev.201xxxxx Search Terms: string, array, length, modifier, strict Some strictly typed languages can catch string / array overflows on compile time against hard coded valu...
X Description: TypeScript Version: 2.7.0-dev.201xxxxx Search Terms: string, array, length, modifier, strict Some strictly typed languages can catch string / array overflows on compile time against hard coded valu...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/23617
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Request: strictier array and string using parenthesis modifiers","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨 -->\r\n\u003c!--\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the CONTRIBUTING guidelines: https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n-->\r\n\r\n\u003c!-- If you have a QUESTION:\r\n THIS IS NOT A FORUM FOR QUESTIONS.\r\n Ask questions at http://stackoverflow.com/questions/tagged/typescript\r\n or https://gitter.im/Microsoft/TypeScript\r\n-->\r\n\r\n\u003c!-- If you have a SUGGESTION:\r\n Most suggestion reports are duplicates, please search extra hard before logging a new suggestion.\r\n See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md\r\n-->\r\n\r\n\u003c!-- If you have a BUG:\r\n Please fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 2.7.0-dev.201xxxxx\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** string, array, length, modifier, strict\r\n\r\nSome strictly typed languages can catch string / array overflows on compile time against hard coded values, and might help catching some bugs early on. Usually when creating public APIs, sooner or later, you have to implement a max length for either strings or array items, and while you can catch the error AFTER you've made the request, you would have been able to avoid it at the first place.\r\nThis helps with validation libraries as well, such as Joi, that can create highly dynamic object schemas.\r\n\r\n\r\n\r\n**Code**\r\n\r\n```ts\r\ntype LimitedString = string(3);\r\n\r\nlet limitedString: LimitedString = '1234' // error, LimitedString expects at most 3 characters\r\nlimitedString = '12' // would work (or not?)\r\n\r\ntype LimitedArray = Array(3)\u003c{ something: string }>\r\n\r\nlet limitedArray: LimitedArray = [{ something: '' }, { something: '' }, { something: '' }, { something: '' }] // error, LimitedArray expects at most 3 members\r\n\r\ntype LookupStates = {\r\n [index: string(2)]: string\r\n}\r\n\r\n// This is useful when you have a normalized array or lookup table, for example\r\nconst states: LookupStates = {\r\n 'KS': 'Kansas',\r\n 'IA': 'Iowa'\r\n}\r\n\r\nstates['IOWA'] // error\r\n```","author":{"url":"https://github.com/pocesar","@type":"Person","name":"pocesar"},"datePublished":"2018-04-22T21:22:57Z","url":"https://github.com/microsoft/TypeScript/issues/23617"}
| 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:f79bc702-22dd-4d13-7b50-f72a05ddaea7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB84:36A3E:9F40E5:D67CC6:6B00ED26 |
| html-safe-nonce | 242dde8d1beca48351b7f4e4268c6e2751dedc5aa603cc3611b2b10408c32952 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjg0OjM2QTNFOjlGNDBFNTpENjdDQzY6NkIwMEVEMjYiLCJ2aXNpdG9yX2lkIjoiNDY5OTkyODAwMDIxOTYzOTA3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2a31a7322061178fa18040f85a09fad3ed322c5cbc7af0ee689f1678e6408a76 |
| hovercard-subject-tag | issue:316614571 |
| 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/23617/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a221cdd1803bbff7875b3c7406f5dc107c7dbcd380875693a0c5d82799269320/microsoft/TypeScript/issues/23617 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a221cdd1803bbff7875b3c7406f5dc107c7dbcd380875693a0c5d82799269320/microsoft/TypeScript/issues/23617 |
| og:image:alt | TypeScript Version: 2.7.0-dev.201xxxxx Search Terms: string, array, length, modifier, strict Some strictly typed languages can catch string / array overflows on compile time against hard coded valu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pocesar |
| 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