René's URL Explorer Experiment


Title: Subtraction types · Issue #4183 · microsoft/TypeScript · GitHub

Open Graph Title: Subtraction types · Issue #4183 · microsoft/TypeScript

X Title: Subtraction types · Issue #4183 · microsoft/TypeScript

Description: Another type-safety measure. Sometimes it's desired to limit what developers can do with a value. Not allowing them to get to certain properties of it looks sufficient. Example: We render HTML elements to PDF on the client side. In order...

Open Graph Description: Another type-safety measure. Sometimes it's desired to limit what developers can do with a value. Not allowing them to get to certain properties of it looks sufficient. Example: We render HTML elem...

X Description: Another type-safety measure. Sometimes it's desired to limit what developers can do with a value. Not allowing them to get to certain properties of it looks sufficient. Example: We render HTML ...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/4183

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Subtraction types","articleBody":"Another type-safety measure. Sometimes it's desired to limit what developers can do with a value. Not allowing them to get to certain properties of it looks sufficient. \r\n\r\nExample: We render HTML elements to PDF on the client side. In order to do so we need to run `element.getBoundingClientRect` to get a bounding box in effect. It is an expensive operation that we wish could only be done once and then the result of it would be passed around along with the element to be rendered. Unfortunately nothing stops developers from ignoring that result and running the same method again and again as long as they can get to `element.getBoundingClientRect`. Now I wish I could strip that method so no-one can see it once the box is calculated. Subtaction types would solve the problem.\r\n\r\n``` typescript\r\ntype HTMLDivSpecifics = HTMLDivElement - Element;\r\n```\r\n\r\n# Proposal\r\n\r\nadd a type operator that produces a new type out of 2 given types according to the rules that follow:\r\n\r\n```typescript\r\ntype C = A - B;\r\n```\r\nThis feature would require a new **negated** type like `number ~ string` which is a `number` that cannot take `number \u0026 string`.\r\n\r\nAs far as the precedence of new type operator, it should go:\r\n\r\n1. intersection `\u0026`\r\n2. union `|`\r\n3. subtraction `-`\r\n\r\nso that `number \u0026 boolean | string - string`, means `((number \u0026 boolean) | string) - string`\r\n\r\n### Generics\r\n- should produce a yet to be resolved type, should be stored as an expression which will produce either a type or an error when all type parameters are known\r\n\r\n```typescript\r\ntype Minus\u003cA, B\u003e = A - B; // yet to be calculated\r\n```\r\n\r\n###   Primitives\r\n- if the left type (minued) isn't a sub-type of the right type (subtrahend) the `-` operation should result to an type error\r\n- `never` and `any` should be specially handled\r\n\r\n```typescript\r\ntype C = number - number; // {}\r\ntype C = number - {}; // number\r\ntype C = {} - number; // error\r\ntype C = number - string; // error\r\ntype C = number - 0; // number ~ 0\r\n\r\ntype C = number | string - boolean; // error\r\ntype C = number - void | null | undefined; // error\r\n\r\ntype C = number - any; // {}\r\ntype C = any - any; // any\r\ntype C = any - number; // any ~ number\r\ntype C = any - never; // error;\r\ntype C = never - any; // error;\r\ntype C = number - never; // error\r\ntype C = never - number; // error\r\ntype C = never - never; // error\r\n\r\ntype C = number | string - string; // number\r\ntype C = number - number | string; // {}\r\ntype C = number | string - {}; // number | string\r\n\r\ntype C = number \u0026 string - boolean; // error\r\ntype C = number \u0026 string - string; // number ~ string\r\n\r\n```\r\n\r\n### Products\r\n- only matching properties should be considered, non-matching properties of the left type should stay intact, non-matching properties of the right type should be disregarded\r\n- if the names of 2 properties match their types are subject for `-` operation that produces the type of the resulting property of the same name \r\n- if applying `-` on 2 properties of the same name gives `{}`, the property gets dropped from the resulting type\r\n\r\n```typescript\r\ntype C = {} - { x: number }; // {}\r\ntype C = { x: number } - {}; // { x: number }\r\ntype C = { x: {} } - { x: number }; // error\r\ntype C = { x: number } - { x: {} }; // { x: number }\r\ntype C = { x: number } - { y: number }; // { x: number }\r\ntype C = { x: number } - { x: number }; // {}\r\ntype C = { x: number | string } - { x: string }; // { x: number }\r\ntype C = { x: number \u0026 string } - { x: string }; // { x: number ~ string }\r\ntype C = { x: number } - { x: string }; // error\r\n```\r\n\r\n### Functions (2 certain signatures)\r\n- both functions must have the same number of parameters, otherwise it's an error\r\n- types of corresponding parameters are subject to the `-` operator\r\n- types of results must 100% match and should be kept intact, otherwise it's an error\r\n- if `-` on 2 parameters gives `{}` the resulting parameter is `{}`\r\n- if all resulting parameters are `{}` the resulting type is `{}`\r\n\r\n```typescript\r\ntype C = ((x: number) =\u003e string) - ((x: number) =\u003e string); // {}\r\ntype C = ((x: number) =\u003e number) - ((x: number) =\u003e number); // (x: {}) =\u003e number\r\ntype C = ((x: number | string) =\u003e string) - ((x: string) =\u003e string); // (x: number) =\u003e string\r\ntype C = ((x: number) =\u003e string) - ((x: string) =\u003e string); // error\r\ntype C = ((x: number | string) =\u003e string) - (() =\u003e string); // error\r\ntype C = (() =\u003e string) - ((x: number) =\u003e string); // error\r\n```\r\n\r\n### Overloads\r\n- to be continued...\r\n","author":{"url":"https://github.com/zpdDG4gta8XKpMCd","@type":"Person","name":"zpdDG4gta8XKpMCd"},"datePublished":"2015-08-06T08:51:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":80},"url":"https://github.com/4183/TypeScript/issues/4183"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d2d7dd16-3dcd-eef3-597d-958ea71f65ea
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8632:189C82:31AD09D:32FB3E9:6A632214
html-safe-nonce5b48db4980db76df0f6d30498c72956bc9593952dd360968d984e57a1d2d3bea
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjMyOjE4OUM4MjozMUFEMDlEOjMyRkIzRTk6NkE2MzIyMTQiLCJ2aXNpdG9yX2lkIjoiOTAyMjc2ODM2Njk0NDk4NTYyMSIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9
visitor-hmac71fe2dfbd001209bbde3b12cb185839045c134bb642c2929d06c918ece5df4c8
hovercard-subject-tagissue:99388722
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/4183/issue_layout
twitter:imagehttps://opengraph.githubassets.com/624891289e8882a8048cdec77c49e53f0eaab8c226522e3c886966fc516e50ae/microsoft/TypeScript/issues/4183
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/624891289e8882a8048cdec77c49e53f0eaab8c226522e3c886966fc516e50ae/microsoft/TypeScript/issues/4183
og:image:altAnother type-safety measure. Sometimes it's desired to limit what developers can do with a value. Not allowing them to get to certain properties of it looks sufficient. Example: We render HTML elem...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamezpdDG4gta8XKpMCd
hostnamegithub.com
expected-hostnamegithub.com
None1a6c056e02f174fffc096c521ec0ff6fb83e40a2ec8cb8875466ec1524872dd6
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release6a93e25585f487ddff9e3996c06d5b869d6e1828
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/4183#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F4183
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F4183
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/4183
Reloadhttps://github.com/microsoft/TypeScript/issues/4183
Reloadhttps://github.com/microsoft/TypeScript/issues/4183
Please reload this pagehttps://github.com/microsoft/TypeScript/issues/4183
microsoft https://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Notifications https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Fork 13.6k https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Star 110k https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Code https://github.com/microsoft/TypeScript
Issues 5k+ https://github.com/microsoft/TypeScript/issues
Pull requests 21 https://github.com/microsoft/TypeScript/pulls
Actions https://github.com/microsoft/TypeScript/actions
Projects https://github.com/microsoft/TypeScript/projects
Models https://github.com/microsoft/TypeScript/models
Wiki https://github.com/microsoft/TypeScript/wiki
Security and quality 0 https://github.com/microsoft/TypeScript/security
Insights https://github.com/microsoft/TypeScript/pulse
Code https://github.com/microsoft/TypeScript
Issues https://github.com/microsoft/TypeScript/issues
Pull requests https://github.com/microsoft/TypeScript/pulls
Actions https://github.com/microsoft/TypeScript/actions
Projects https://github.com/microsoft/TypeScript/projects
Models https://github.com/microsoft/TypeScript/models
Wiki https://github.com/microsoft/TypeScript/wiki
Security and quality https://github.com/microsoft/TypeScript/security
Insights https://github.com/microsoft/TypeScript/pulse
Subtraction typeshttps://github.com/microsoft/TypeScript/issues/4183#top
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Proposal%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/zpdDG4gta8XKpMCd
zpdDG4gta8XKpMCdhttps://github.com/zpdDG4gta8XKpMCd
on Aug 6, 2015https://github.com/microsoft/TypeScript/issues/4183#issue-99388722
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Proposal%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.