René's URL Explorer Experiment


Title: Suggestion: Type assertion operator (!) with mapped types · Issue #13253 · microsoft/TypeScript · GitHub

Open Graph Title: Suggestion: Type assertion operator (!) with mapped types · Issue #13253 · microsoft/TypeScript

X Title: Suggestion: Type assertion operator (!) with mapped types · Issue #13253 · microsoft/TypeScript

Description: TypeScript Version: 2.1.1 Also relates to #12424 I recently spent some time looking at the discussion on a safe navigation ?. operator in typescript/javascript (see #16, and https://esdiscuss.org/topic/existential-operator-null-propagati...

Open Graph Description: TypeScript Version: 2.1.1 Also relates to #12424 I recently spent some time looking at the discussion on a safe navigation ?. operator in typescript/javascript (see #16, and https://esdiscuss.org/t...

X Description: TypeScript Version: 2.1.1 Also relates to #12424 I recently spent some time looking at the discussion on a safe navigation ?. operator in typescript/javascript (see #16, and https://esdiscuss.org/t...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: Type assertion operator (!) with mapped types","articleBody":"**TypeScript Version:**  2.1.1 \r\n\r\nAlso relates to https://github.com/Microsoft/TypeScript/issues/12424\r\n\r\nI recently spent some time looking at the discussion on a safe navigation `?.` operator in typescript/javascript (see https://github.com/Microsoft/TypeScript/issues/16, and https://esdiscuss.org/topic/existential-operator-null-propagation-operator). Then it struck me that ES6 proxies could be a solution that didn't require new language operators. Wrote something working together, and also found this existing npm package: https://www.npmjs.com/package/safe-proxy. In summary, you'd be able to write\r\n\r\n```typescript\r\n// Safe (only does actual property access if underlying object is valid)\r\nsafe(a).b.c().d[0]\r\n\r\n// ...instead of the functionally equivalent but unsafe\r\na.b.c().d[0]\r\n```\r\n\r\nNow, how do I type annotate this? At first, I thought maybe the new mapped types in Typescript 2.1  could be used, but then I've come to believe that it isn't possible currently (please let me know how to do this otherwise). What I miss is a generalized way of narrowing optional types under `---strictNullChecks`. \r\n\r\nFor example, let's consider using the `mapObject` from the the [Typescript 2.1 release wiki writeup](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html), with optional properties:\r\n\r\n```typescript\r\nconst names:{ foo: string, bar?: string} = { foo: \"\" };\r\nmapObject(names, s => s.length)\r\n```\r\n\r\nThis results in a TS2345 error (basically `bar` can't be optional)\r\n\r\nNow, back to the `SafeProxy` type. The best I can come up with today is\r\n\r\n```typescript\r\ntype SafeProxy\u003cT> = {\r\n    [P in keyof T]: SafeProxy\u003cT[P]&any>;\r\n};\r\n```\r\n\r\n...which is marginally better than just `any`.\r\n\r\nI would want (and need for my example above) to define something like below. NOTE: the assertion operator here is made-up-syntax. I suggested an exclamation mark after the actual type, but this could obviously be debated.\r\n\r\n```typescript\r\ntype SafeProxy\u003cT> = {\r\n    [P in keyof T]: SafeProxy\u003cT[P]!>;\r\n};\r\n```\r\n\r\nInterestingly it would kind of enable the reverse of `Partial\u003cT>`:\r\n\r\n```typescript\r\n// existing in lib.d.ts\r\ntype Partial\u003cT> = {\r\n    [P in keyof T]?: T[P];\r\n};\r\n\r\n// potential\r\ntype Complete\u003cT> = {\r\n   [P in keyof T]: T[P]!;\r\n}\r\n```\r\n\r\nSide note: As I intend the `SafeProxy` class to implement `Symbol.toPrimitive`, no trailing `__value` or similar would be needed. This seems to play well with typescript primitives though\r\n\r\nSome other usages (that I guess all play pretty well with `--strictNullChecks`)\r\n* advanced assertion style functions\r\n* default mechanism functions\r\n","author":{"url":"https://github.com/staeke","@type":"Person","name":"staeke"},"datePublished":"2017-01-02T13:18:29Z","url":"https://github.com/microsoft/TypeScript/issues/13253"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:db3b618c-4e89-8bb4-ce8d-ad1767d1d9f7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCB3A:34EA7D:C2D2DB:FA813F:6B00EB56
html-safe-noncea8bbebcc605bf149eb544364ae444ef66509f703874781840e8bc603c879e0b9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjNBOjM0RUE3RDpDMkQyREI6RkE4MTNGOjZCMDBFQjU2IiwidmlzaXRvcl9pZCI6Ijg2MzgxNjIwOTQzNjcyMzg5OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf563d1c49196e52baf13bda0d8a4d935531c37deef32631ba3f039f887431eb6
hovercard-subject-tagissue:198334549
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/13253/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d44adc97b71acfaaebf1dd554b6f2f007a84d7b507190b32425be19546b6c5dd/microsoft/TypeScript/issues/13253
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d44adc97b71acfaaebf1dd554b6f2f007a84d7b507190b32425be19546b6c5dd/microsoft/TypeScript/issues/13253
og:image:altTypeScript Version: 2.1.1 Also relates to #12424 I recently spent some time looking at the discussion on a safe navigation ?. operator in typescript/javascript (see #16, and https://esdiscuss.org/t...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamestaeke
hostnamegithub.com
expected-hostnamegithub.com
None4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc
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
release9983dd5da06943f833c971dd5b6bc988e2858be5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/13253#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F13253
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F13253
Sign uphttps://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/13253
Reloadhttps://github.com/microsoft/TypeScript/issues/13253
Reloadhttps://github.com/microsoft/TypeScript/issues/13253
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests308 (308)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/13253
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/13253
Suggestion: Type assertion operator (!) with mapped typeshttps://github.com/microsoft/TypeScript/issues/13253#top
https://github.com/staeke
Staffan Eketorp (staeke)https://github.com/staeke
on Jan 2, 2017https://github.com/microsoft/TypeScript/issues/13253#issue-198334549
#12424https://github.com/microsoft/TypeScript/issues/12424
#16https://github.com/microsoft/TypeScript/issues/16
https://esdiscuss.org/topic/existential-operator-null-propagation-operatorhttps://esdiscuss.org/topic/existential-operator-null-propagation-operator
https://www.npmjs.com/package/safe-proxyhttps://www.npmjs.com/package/safe-proxy
Typescript 2.1 release wiki writeuphttps://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html
https://github.com/zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)https://github.com/zpdDG4gta8XKpMCd
on Jan 2, 2017https://github.com/microsoft/TypeScript/issues/13253#issuecomment-270006814
#4183https://github.com/microsoft/TypeScript/issues/4183
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jan 5, 2017https://github.com/microsoft/TypeScript/issues/13253#issuecomment-270738788
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jan 5, 2017https://github.com/microsoft/TypeScript/issues/13253#issuecomment-270740822
#12596https://github.com/microsoft/TypeScript/issues/12596
#12769https://github.com/microsoft/TypeScript/issues/12769
https://github.com/staeke
Staffan Eketorp (staeke)https://github.com/staeke
on Jan 6, 2017https://github.com/microsoft/TypeScript/issues/13253#issuecomment-270860734
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
Staffan Eketorp (staeke)https://github.com/staeke
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 6, 2017https://github.com/microsoft/TypeScript/issues/13253#event-913790688
https://github.com/masaeedu
Asad Saeeduddin (masaeedu)https://github.com/masaeedu
on Apr 5, 2017https://github.com/microsoft/TypeScript/issues/13253#issuecomment-291754640
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Mar 2, 2018https://github.com/microsoft/TypeScript/issues/13253#issuecomment-370014674
NonNullable typehttps://github.com/Microsoft/TypeScript/pull/21847
microsofthttps://github.com/microsoft
on Jul 3, 2018https://github.com/microsoft/TypeScript/issues/13253#event-1712799655
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/13253
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/13253
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.