René's URL Explorer Experiment


Title: Safe type assertion (upcast / widening) operator · Issue #56235 · microsoft/TypeScript · GitHub

Open Graph Title: Safe type assertion (upcast / widening) operator · Issue #56235 · microsoft/TypeScript

X Title: Safe type assertion (upcast / widening) operator · Issue #56235 · microsoft/TypeScript

Description: 🔍 Search Terms as, satisfies, type assertion, type casting ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime behavior of existing JavaScript code This could b...

Open Graph Description: 🔍 Search Terms as, satisfies, type assertion, type casting ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime behavior ...

X Description: 🔍 Search Terms as, satisfies, type assertion, type casting ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime b...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Safe type assertion (upcast / widening) operator","articleBody":"### 🔍 Search Terms\n\nas, satisfies, type assertion, type casting\n\n### ✅ Viability Checklist\n\n- [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code\n- [X] This wouldn't change the runtime behavior of existing JavaScript code\n- [X] This could be implemented without emitting different JS based on the types of the expressions\n- [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\n- [X] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals\n\n### ⭐ Suggestion\n\nI suggest adding a safe type assertion operator, a kind of middle ground between current `as` and `satisfies`.\r\n\r\n- Like `as`, it should cast the expression to the asserted type\r\n- Like `satisfies`, it should only allow assertion if the asserted type is wider than the expression type\r\n\r\nHere's what it might look like:\r\n\r\n```ts\r\ntype Foo = { a: number }\r\n\r\nconst foo1 = { a: 1 } as! Foo // OK. foo1: Foo\r\n\r\nconst foo2 = { a: 1, b: 2 } as! Foo // OK, foo2: Foo\r\n\r\nconst foo3 = { b: 2 } as! Foo // Error, { b: number } is not assignable to Foo\r\n\r\nconst foo4 = { } as! Foo // Error, {} is not assignable to Foo\r\n```\r\n\n\n### 📃 Motivating Example\n\nFor example, such operator will allow to safely give named types to expressions without declaring extra variables or helper functions.\r\n\r\nConsider an async function `f` that returns an object of type `Foo`:\r\n\r\n```ts\r\ntype Foo = { a: number }\r\n\r\nconst f = async () => ({ a: 1 })\r\n```\r\n\r\nI want the returned object to strictly be of `Foo` type, how do I enforce this?\r\n\r\n1) Hard code the return type\r\n\r\n```ts\r\nconst f = async (): Promise\u003cFoo> => ({ a: 1 })\r\n```\r\n\r\nThe problem here is that I must write `Promise\u003cFoo>` instead of just `Foo`, but the `Promise` part can be inferred just fine. In real world these generics can be arbitrarily complex.\r\n\r\n2) Declare a variable\r\n\r\n```ts\r\nconst f = async () => {\r\n  const result: Foo = { a: 1 }\r\n\r\n  return result\r\n}\r\n```\r\n\r\nThis is better than retyping generics but still pretty verbose.\r\n\r\n3) Use a helper function\r\n\r\n```ts\r\nconst safeAssert = \u003cT>(value: T): T => value\r\n\r\nconst f = async () => safeAssert\u003cFoo>({ a: 1 })\r\n```\r\n\r\nThis is ok but still requires writing/importing helper functions.\r\n\r\n`as` is not an option here because it's unsafe, `satisfies` is neither because it doesn't name the type. Naming a type can be important for documentation purposes, this proposal allows to do this with less boilerplate.\r\n\r\n```ts\r\nconst f = async () => ({ a: 1}) as! Foo // f: () => Promise\u003cFoo>\r\n```\r\n\n\n### 💻 Use Cases\n\nAs described above, this feature can be used to safely cast expressions to specified types. A practical example when it can be useful is naming a type in an expression. Currently this is only covered by custom helper functions such as `\u003cT>(value: T): T => value`.\r\n","author":{"url":"https://github.com/bgenia","@type":"Person","name":"bgenia"},"datePublished":"2023-10-27T22:13:41Z","url":"https://github.com/microsoft/TypeScript/issues/56235"}

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:8b3f32dd-8f47-1b7f-8331-7531dba197ba
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA474:29FFA9:293558E:342FBCD:6B019E90
html-safe-noncebde98dd9a907197f166dc8404ff8970af93b3ce0300ce6a0ad30ba86ed4c2206
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDc0OjI5RkZBOToyOTM1NThFOjM0MkZCQ0Q6NkIwMTlFOTAiLCJ2aXNpdG9yX2lkIjoiNzkyODM5NTAxMzY5MTU1MjE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaceda220697ec8d992abe338d353cc5531083de4bf7c2b4a3df2157ae30c9a3d9a
hovercard-subject-tagissue:1966251776
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/56235/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f246a6354d55872739960da157026f92f3e552056939bf65f4ea7ed6916aba9e/microsoft/TypeScript/issues/56235
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f246a6354d55872739960da157026f92f3e552056939bf65f4ea7ed6916aba9e/microsoft/TypeScript/issues/56235
og:image:alt🔍 Search Terms as, satisfies, type assertion, type casting ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime behavior ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebgenia
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/56235#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F56235
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%2F56235
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/56235
Reloadhttps://github.com/microsoft/TypeScript/issues/56235
Reloadhttps://github.com/microsoft/TypeScript/issues/56235
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)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/56235
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/56235
Safe type assertion (upcast / widening) operatorhttps://github.com/microsoft/TypeScript/issues/56235#top
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/bgenia
bgeniahttps://github.com/bgenia
on Oct 27, 2023https://github.com/microsoft/TypeScript/issues/56235#issue-1966251776
https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goalshttps://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 27, 2023https://github.com/microsoft/TypeScript/issues/56235#issuecomment-1783574806
#47920https://github.com/microsoft/TypeScript/issues/47920
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
on Oct 27, 2023https://github.com/microsoft/TypeScript/issues/56235#event-10796229315
https://github.com/bgenia
bgeniahttps://github.com/bgenia
on Oct 27, 2023https://github.com/microsoft/TypeScript/issues/56235#issuecomment-1783575922
#47920https://github.com/microsoft/TypeScript/issues/47920
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 27, 2023https://github.com/microsoft/TypeScript/issues/56235#issuecomment-1783576966
https://github.com/bgenia
bgeniahttps://github.com/bgenia
on Oct 27, 2023https://github.com/microsoft/TypeScript/issues/56235#issuecomment-1783582827
https://github.com/Josh-Cena
Joshua Chen (Josh-Cena)https://github.com/Josh-Cena
on Oct 28, 2023https://github.com/microsoft/TypeScript/issues/56235#issuecomment-1783638532
#9998https://github.com/microsoft/TypeScript/issues/9998
https://github.com/raythurnvoid
Ray Thurn Void (raythurnvoid)https://github.com/raythurnvoid
on Jan 4, 2024https://github.com/microsoft/TypeScript/issues/56235#issuecomment-1877407785
https://github.com/saltman424
Sander Altman (saltman424)https://github.com/saltman424
on Mar 28, 2024https://github.com/microsoft/TypeScript/issues/56235#issuecomment-2025651824
Joshua Chen (@Josh-Cena)https://github.com/Josh-Cena
#13626https://github.com/microsoft/TypeScript/issues/13626
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Jul 31, 2025https://github.com/microsoft/TypeScript/issues/56235#issuecomment-3141256372
#61789 (comment)https://github.com/microsoft/TypeScript/issues/61789#issuecomment-2941843696
#51853 (comment)https://github.com/microsoft/TypeScript/issues/51853#issuecomment-1345638692
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jul 31, 2025https://github.com/microsoft/TypeScript/issues/56235#event-18926813976
https://github.com/5cover
Scover (5cover)https://github.com/5cover
on Mar 27, 2026https://github.com/microsoft/TypeScript/issues/56235#issuecomment-4145657649
https://github.com/mkantor
Matt Kantor (mkantor)https://github.com/mkantor
on May 25, 2026https://github.com/microsoft/TypeScript/issues/56235#issuecomment-4533848101
1https://github.com/microsoft/TypeScript/issues/56235#user-content-fn-1-4c13fe56cb6321441d7821deca9cd99a
↩https://github.com/microsoft/TypeScript/issues/56235#user-content-fnref-1-4c13fe56cb6321441d7821deca9cd99a
https://github.com/michaelboyles
Michael (michaelboyles)https://github.com/michaelboyles
on Jun 20, 2026https://github.com/microsoft/TypeScript/issues/56235#issuecomment-4757663281
Matt Kantor (@mkantor)https://github.com/mkantor
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/56235
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/56235
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%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.