Title: Allow intersected numbers to be used in arithmetics & element access · Issue #4372 · microsoft/TypeScript · GitHub
Open Graph Title: Allow intersected numbers to be used in arithmetics & element access · Issue #4372 · microsoft/TypeScript
X Title: Allow intersected numbers to be used in arithmetics & element access · Issue #4372 · microsoft/TypeScript
Description: I was experimenting with intersection types and primitives, and I discovered that when you create an intersection type with a number, you can't use it in arithmetics and element access: type extendedNumber = number & { extended: any }; l...
Open Graph Description: I was experimenting with intersection types and primitives, and I discovered that when you create an intersection type with a number, you can't use it in arithmetics and element access: type extend...
X Description: I was experimenting with intersection types and primitives, and I discovered that when you create an intersection type with a number, you can't use it in arithmetics and element access: type ex...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/4372
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow intersected numbers to be used in arithmetics & element access","articleBody":"I was experimenting with intersection types and primitives, and I discovered that when you create an intersection type with a number, you can't use it in arithmetics and element access:\n\n``` typescript\ntype extendedNumber = number & { extended: any };\nlet a: extendedNumber;\nlet obj: any;\n\na + 1; // Operator '+' cannot be applied to types 'number & { extended: any }' and 'number'.\nobj[a]; // An index expression argument must be of type 'string', 'number', 'symbol, or 'any'.\n```\n\nThough you can't create properties on numbers, this can be useful to add brands to numbers, like this:\n\n``` typescript\ntype int = number & { __intBrand: void };\nfunction int(value: number) {\n return \u003cint> (value | 0);\n}\n```\n\nCurrently intersections are only allowed on these locations if all parts of the intersection are number or string, but that rule should only apply to union types. Suggestion: for intersection types (at least) one type should be number (or string) if it's used in arithmetics or element access.\n\nI've implemented a fix in #4373.\n","author":{"url":"https://github.com/ivogabe","@type":"Person","name":"ivogabe"},"datePublished":"2015-08-20T06:23:38Z","url":"https://github.com/microsoft/TypeScript/issues/4372"}
| 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:071f40bf-442d-8a6c-18e4-12fb78faf495 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D714:33D24F:9624F7:C22105:6B00F1B8 |
| html-safe-nonce | 765e967bd9a7844cdb84165096ffa600f845d15b887b33cde5b0e8d5eae5aac6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzE0OjMzRDI0Rjo5NjI0Rjc6QzIyMTA1OjZCMDBGMUI4IiwidmlzaXRvcl9pZCI6IjQyMjgyMTkxMTIyNjM4NDAxODQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3f5da0767ced71c41e069e7189df4ef9f97151b66811c9adc5c71dada0ac92fa |
| hovercard-subject-tag | issue:102071041 |
| 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/4372/issue_layout |
| twitter:image | https://opengraph.githubassets.com/47fab1837b921d3231b928e77fcb6805e41282ddd6634d8ae894c2a6d7c8fdf1/microsoft/TypeScript/issues/4372 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47fab1837b921d3231b928e77fcb6805e41282ddd6634d8ae894c2a6d7c8fdf1/microsoft/TypeScript/issues/4372 |
| og:image:alt | I was experimenting with intersection types and primitives, and I discovered that when you create an intersection type with a number, you can't use it in arithmetics and element access: type extend... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ivogabe |
| 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