René's URL Explorer Experiment


Title: `asserts x is type` doesn't work when using arrow functions · Issue #34523 · microsoft/TypeScript · GitHub

Open Graph Title: `asserts x is type` doesn't work when using arrow functions · Issue #34523 · microsoft/TypeScript

X Title: `asserts x is type` doesn't work when using arrow functions · Issue #34523 · microsoft/TypeScript

Description: TypeScript Version: 3.7.0-dev.20191016 Search Terms: assertion signatures, asserts, asserts is type Code function isString1(val: any): asserts val is string { if (typeof val !== "string") throw "Nope" } const isString2 = (val: any): asse...

Open Graph Description: TypeScript Version: 3.7.0-dev.20191016 Search Terms: assertion signatures, asserts, asserts is type Code function isString1(val: any): asserts val is string { if (typeof val !== "string") throw "No...

X Description: TypeScript Version: 3.7.0-dev.20191016 Search Terms: assertion signatures, asserts, asserts is type Code function isString1(val: any): asserts val is string { if (typeof val !== "string")...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`asserts x is type` doesn't work when using arrow functions","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.7.0-dev.20191016 \r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** assertion signatures, asserts, asserts is type\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction isString1(val: any): asserts val is string {\r\n    if (typeof val !== \"string\") throw \"Nope\"\r\n} \r\n\r\nconst isString2 = (val: any): asserts val is string => {\r\n    if (typeof val !== \"string\") throw \"Nope\"\r\n} \r\n\r\nconst x: any = \"3\";\r\n\r\nisString1(x);\r\nisString2(x);\r\n\r\nx.toUpperCase();\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nCompiles, infers that `x` is a string, both when using only `isString1` or `isString2`\r\n\r\n**Actual behavior:**\r\n\r\nCompile error on `isString2`:\r\n\r\n```\r\nAssertions require every name in the call target to be declared with an explicit type annotation.(2775)\r\n```\r\n\r\n**Playground Link:** [1⃣ playground](http://www.typescriptlang.org/play/?ts=Nightly&ssl=15&ssc=1&pln=1&pc=1#code/GYVwdgxgLglg9mABDAzgZSgJxmA5gRgAoA3AQwBsAuRUsATwEprSUUBTTKFRM85blFhy5EAbwBQiKcmCJCUOgAc2cWb0QBCALxbEAIkHY8ehoigALTHADu+gHJxle8QF9E48RASD+GI7gAmRF0SCmZ6JhpWDi4eCn5EQ2FggD4xSWkYWXklFTV47V0DIWNTCytbPQcnV3dPbyhEAA9wumD9AGY9AG4PVD9hIiaGXv6SwMJh3vEmgDooOABVRWVMAGEWNkIR8SA)\r\n\r\n**Related Issues:** #33743 \r\n\r\n**Context**\r\n\r\nIn principle the above problem is easy to work around, however, the result of it is when type checkers are stored on objects, the above error returns as is demonstrated in [2⃣ this playground](http://www.typescriptlang.org/play/?ts=Nightly#code/C4TwDgpgBAKuEGEAWEDGBrCAnAPDAfFALxQDeAUFFVABQBuAhgDYBcUDAdiAJRsMDO-bMH5RGTKAEtRMANzkAvuXIAzAK4dUwSQHsOUALYNMcSHnw1UegCZt6zPl27FCAIx06mETr1jxkaJi4BGSU1FgQwGpY+uqa2nq04o48odTpUiq0AIRWHNb2TNzOwEhYOgDuUBwQVQCiWOVYNABEAPI6YPwt3GFUCuyinCCKynn8wFL8AMrAWJIcAOZspogoGNg4E-NLhCRGJvA0hSnORISgkDpZ4sREJC3bC4s9Y3oTUKjrQfwAjMRkKazHaLKBKcaTL6BbD8ABMbFIQLmzxW-m+myeuzBAMR0mBzzB5Ahn3RWH4AGYEUiQWxLhBrtSCQMSLiZsiloTiVCNmSACw4xkcgYCT7vYBvDgfAAeKQBLXJLXk5Dx7MWNCl3Hk3J+vwAdCqQerNVAAPQmqD8JA6NRMazVHSTMDlaxqVDQKwGMCSLxQbBNImkuH6tmGjVawPk4P4pZG8PQvlR1Wx03my3W232x3O13unSe73QP06LDKKW64A6ACqYEgWAQAggNE15CAA). Note how the very same function fails when it is stored in an object, unless the type is provided explicitly.\r\n","author":{"url":"https://github.com/mweststrate","@type":"Person","name":"mweststrate"},"datePublished":"2019-10-16T20:24:00Z","url":"https://github.com/microsoft/TypeScript/issues/34523"}

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:9c04205b-1f63-1090-613f-6b2c12125455
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB684:1087D4:AB4818:E5B216:6B00F21C
html-safe-nonce86887c6c768bba2ff016ffaa3e7b24b825b96dce5f6eef5287e50eb8ac99bb9d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjg0OjEwODdENDpBQjQ4MTg6RTVCMjE2OjZCMDBGMjFDIiwidmlzaXRvcl9pZCI6IjI5NTY1MDU4MDQ0NTYzOTExOTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac268e2b0a91f1471c0cab93e53cce1a89ef9bce267dc109c7249b2b53492c5a45
hovercard-subject-tagissue:508079201
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/34523/issue_layout
twitter:imagehttps://opengraph.githubassets.com/abb6862f809a17c8f5185e0b745440832e663cc51839d1a06ae61e567780ff91/microsoft/TypeScript/issues/34523
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/abb6862f809a17c8f5185e0b745440832e663cc51839d1a06ae61e567780ff91/microsoft/TypeScript/issues/34523
og:image:altTypeScript Version: 3.7.0-dev.20191016 Search Terms: assertion signatures, asserts, asserts is type Code function isString1(val: any): asserts val is string { if (typeof val !== "string") throw "No...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemweststrate
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/34523#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F34523
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%2F34523
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/34523
Reloadhttps://github.com/microsoft/TypeScript/issues/34523
Reloadhttps://github.com/microsoft/TypeScript/issues/34523
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/34523
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/34523
asserts x is type doesn't work when using arrow functionshttps://github.com/microsoft/TypeScript/issues/34523#top
Design LimitationConstraints of the existing architecture prevent this from being fixedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Design%20Limitation%22
https://github.com/mweststrate
Michel Weststrate (mweststrate)https://github.com/mweststrate
on Oct 16, 2019https://github.com/microsoft/TypeScript/issues/34523#issue-508079201
1⃣ playgroundhttp://www.typescriptlang.org/play/?ts=Nightly&ssl=15&ssc=1&pln=1&pc=1#code/GYVwdgxgLglg9mABDAzgZSgJxmA5gRgAoA3AQwBsAuRUsATwEprSUUBTTKFRM85blFhy5EAbwBQiKcmCJCUOgAc2cWb0QBCALxbEAIkHY8ehoigALTHADu+gHJxle8QF9E48RASD+GI7gAmRF0SCmZ6JhpWDi4eCn5EQ2FggD4xSWkYWXklFTV47V0DIWNTCytbPQcnV3dPbyhEAA9wumD9AGY9AG4PVD9hIiaGXv6SwMJh3vEmgDooOABVRWVMAGEWNkIR8SA
#33743https://github.com/microsoft/TypeScript/issues/33743
2⃣ this playgroundhttp://www.typescriptlang.org/play/?ts=Nightly#code/C4TwDgpgBAKuEGEAWEDGBrCAnAPDAfFALxQDeAUFFVABQBuAhgDYBcUDAdiAJRsMDO-bMH5RGTKAEtRMANzkAvuXIAzAK4dUwSQHsOUALYNMcSHnw1UegCZt6zPl27FCAIx06mETr1jxkaJi4BGSU1FgQwGpY+uqa2nq04o48odTpUiq0AIRWHNb2TNzOwEhYOgDuUBwQVQCiWOVYNABEAPI6YPwt3GFUCuyinCCKynn8wFL8AMrAWJIcAOZspogoGNg4E-NLhCRGJvA0hSnORISgkDpZ4sREJC3bC4s9Y3oTUKjrQfwAjMRkKazHaLKBKcaTL6BbD8ABMbFIQLmzxW-m+myeuzBAMR0mBzzB5Ahn3RWH4AGYEUiQWxLhBrtSCQMSLiZsiloTiVCNmSACw4xkcgYCT7vYBvDgfAAeKQBLXJLXk5Dx7MWNCl3Hk3J+vwAdCqQerNVAAPQmqD8JA6NRMazVHSTMDlaxqVDQKwGMCSLxQbBNImkuH6tmGjVawPk4P4pZG8PQvlR1Wx03my3W232x3O13unSe73QP06LDKKW64A6ACqYEgWAQAggNE15CAA
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Oct 17, 2019https://github.com/microsoft/TypeScript/issues/34523#issuecomment-542978853
#33622https://github.com/microsoft/TypeScript/pull/33622
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Design LimitationConstraints of the existing architecture prevent this from being fixedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Design%20Limitation%22
on Oct 17, 2019https://github.com/microsoft/TypeScript/issues/34523#event-2721805586
https://github.com/mweststrate
Michel Weststrate (mweststrate)https://github.com/mweststrate
on Oct 17, 2019https://github.com/microsoft/TypeScript/issues/34523#issuecomment-543240357
Michel Weststrate (mweststrate)https://github.com/mweststrate
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 17, 2019https://github.com/microsoft/TypeScript/issues/34523#event-2721845915
Benny Powers (bennypowers)https://github.com/bennypowers
on May 6, 2020https://github.com/microsoft/TypeScript/issues/34523#event-3309981734
style(resolve): appease TShttps://github.com/open-wc/open-wc/commit/85cd3be2ac02c8aca061be88ae988b792b734ff4
85cd3behttps://github.com/open-wc/open-wc/commit/85cd3be2ac02c8aca061be88ae988b792b734ff4
Lars den Bakker (LarsDenBakker)https://github.com/LarsDenBakker
on May 7, 2020https://github.com/microsoft/TypeScript/issues/34523#event-3311657539
style(resolve): appease TShttps://github.com/open-wc/open-wc/commit/0adb4447f90744490cb9ab0759184730eae7d98a
0adb444https://github.com/open-wc/open-wc/commit/0adb4447f90744490cb9ab0759184730eae7d98a
https://github.com/pstrh
pstrhhttps://github.com/pstrh
on Sep 29, 2020https://github.com/microsoft/TypeScript/issues/34523#issuecomment-700491122
#33622 (comment)https://github.com/microsoft/TypeScript/pull/33622#issuecomment-575301357
Douglas Naphas (douglasnaphas)https://github.com/douglasnaphas
on Feb 6, 2022https://github.com/microsoft/TypeScript/issues/34523#event-6015319136
Insist on a RedirectTypehttps://github.com/cdk-turnkey/sredirect/commit/67503767afecbea3dea7d8bfb29073553e866f26
6750376https://github.com/cdk-turnkey/sredirect/commit/67503767afecbea3dea7d8bfb29073553e866f26
https://github.com/Pyrolistical
Pyrolisticalhttps://github.com/Pyrolistical
on Aug 20, 2022https://github.com/microsoft/TypeScript/issues/34523#issuecomment-1221400964
https://github.com/voltrevo
Andrew Morris (voltrevo)https://github.com/voltrevo
on Oct 13, 2022https://github.com/microsoft/TypeScript/issues/34523#issuecomment-1278252191
#33622https://github.com/microsoft/TypeScript/pull/33622
Joe Calzaretta (@jcalz)https://github.com/jcalz
https://github.com/sezanzeb
Tobi (sezanzeb)https://github.com/sezanzeb
on Mar 23, 2023https://github.com/microsoft/TypeScript/issues/34523#issuecomment-1480822760
#53450https://github.com/microsoft/TypeScript/issues/53450
https://github.com/kaspar-p
kaspar poland (kaspar-p)https://github.com/kaspar-p
on Sep 6, 2024https://github.com/microsoft/TypeScript/issues/34523#issuecomment-2334742968
https://github.com/Moriarty47
Moriarty47 (Moriarty47)https://github.com/Moriarty47
on Nov 8, 2024https://github.com/microsoft/TypeScript/issues/34523#issuecomment-2463610142
pstrhhttps://github.com/pstrh
this commenthttps://github.com/microsoft/TypeScript/issues/34523#issuecomment-700491122
Gavin Morrow (gavinmorrow)https://github.com/gavinmorrow
on Sep 13, 2026https://github.com/microsoft/TypeScript/issues/34523#event-31066577888
Fix type assertions causing errorshttps://github.com/gavinmorrow/orion/commit/d97ed4e613333d30a7c3a04f4f228e252d009194
d97ed4ehttps://github.com/gavinmorrow/orion/commit/d97ed4e613333d30a7c3a04f4f228e252d009194
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/34523
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/34523
Design LimitationConstraints of the existing architecture prevent this from being fixedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Design%20Limitation%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.