René's URL Explorer Experiment


Title: Type narrowed to `never`, incorrectly · Issue #27103 · microsoft/TypeScript · GitHub

Open Graph Title: Type narrowed to `never`, incorrectly · Issue #27103 · microsoft/TypeScript

X Title: Type narrowed to `never`, incorrectly · Issue #27103 · microsoft/TypeScript

Description: TypeScript Version: latest Search Terms: n/a Code function f(a?: {}) { if (!a) { // filters out falsy values: // - `null` // - `undefined` // - `false` // - `NaN` // - `0` / `-0` // - `''` return {}; } // here, the type of `a` has been n...

Open Graph Description: TypeScript Version: latest Search Terms: n/a Code function f(a?: {}) { if (!a) { // filters out falsy values: // - `null` // - `undefined` // - `false` // - `NaN` // - `0` / `-0` // - `''` return {...

X Description: TypeScript Version: latest Search Terms: n/a Code function f(a?: {}) { if (!a) { // filters out falsy values: // - `null` // - `undefined` // - `false` // - `NaN` // - `0` / `-0` // - `''` ...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type narrowed to `never`, incorrectly","articleBody":"**TypeScript Version:**  latest\r\n\r\n**Search Terms:** n/a\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction f(a?: {}) {\r\n    if (!a) {\r\n        // filters out falsy values:\r\n        //  - `null`\r\n        //  - `undefined`\r\n        //  - `false`\r\n        //  - `NaN`\r\n        //  - `0` / `-0`\r\n        //  - `''`\r\n        return {};\r\n    }\r\n\r\n    // here, the type of `a` has been narrowed from \"optional {}\"\r\n    // to just \"{} minus `object`\" (object-coercible, ie, anything but null/undefined, but not `object`)\r\n    // effectively, this is `string | number | symbol | boolean | Function`\r\n\r\n    if (typeof a !== 'object') {\r\n        // `a` here could be the following values:\r\n        //   - a function\r\n        //   - `true``\r\n        //   - a non-zero non-`NaN`` number\r\n        //   - a non-empty string\r\n        //   - a symbol\r\n        return a; // however, the type inferred here is `never`\r\n    }\r\n\r\n    // here, `a` has a verifiably certain type of `object`.\r\n    // because of the type guard above.\r\n    return a; // however, the type is reported as `{}` \r\n}\r\n```\r\n\r\n**Expected behavior:** The type of `a` inside the `if` block will be either `{}`, or better, `string | number | symbol | boolean | Function`.\r\n\r\n**Actual behavior:** The type of `a` inside the `if` block is `never`, which is flat out incorrect.\r\n\r\n**Playground Link:** [link](http://www.typescriptlang.org/play/#src=function%20f(a%3F%3A%20%7B%7D)%20%7B%0A%20%20%20%20if%20(!a)%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20filters%20out%20falsy%20values%3A%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60null%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60undefined%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60false%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60NaN%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%600%60%20%2F%20%60-0%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60''%60%0A%20%20%20%20%20%20%20%20return%20%7B%7D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20here%2C%20the%20type%20of%20%60a%60%20has%20been%20narrowed%20from%20%22optional%20%7B%7D%22%0A%20%20%20%20%2F%2F%20to%20just%20%22%7B%7D%20minus%20%60object%60%22%20(object-coercible%2C%20ie%2C%20anything%20but%20null%2Fundefined%2C%20but%20not%20%60object%60)%0A%20%20%20%20%2F%2F%20effectively%2C%20this%20is%20%60string%20%7C%20number%20%7C%20symbol%20%7C%20boolean%20%7C%20Function%60%0A%0A%20%20%20%20if%20(typeof%20a%20!%3D%3D%20'object')%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20%60a%60%20here%20could%20be%20the%20following%20values%3A%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20function%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20%60true%60%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20non-zero%20non-%60NaN%60%60%20number%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20non-empty%20string%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20symbol%0A%20%20%20%20%20%20%20%20return%20a%3B%20%2F%2F%20however%2C%20the%20type%20inferred%20here%20is%20%60never%60%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20here%2C%20%60a%60%20has%20a%20verifiably%20certain%20type%20of%20%60object%60.%0A%20%20%20%20%2F%2F%20because%20of%20the%20type%20guard%20above.%0A%20%20%20%20return%20a%3B%20%2F%2F%20however%2C%20the%20type%20is%20reported%20as%20%60%7B%7D%60%20%0A%7D)\r\n\r\n**Related Issues:** not sure how to search for it\r\n","author":{"url":"https://github.com/ljharb","@type":"Person","name":"ljharb"},"datePublished":"2018-09-14T21:41:56Z","url":"https://github.com/microsoft/TypeScript/issues/27103"}

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:b3a8b816-9661-f1b0-f583-9dbe30d72026
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE238:221EB5:675BBB:8E7EAE:6B04A5DF
html-safe-noncec98f19928dba9ce2eb3ec1b52dc966ba6b065d78a2be9078fb7b9b2db259660f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjM4OjIyMUVCNTo2NzVCQkI6OEU3RUFFOjZCMDRBNURGIiwidmlzaXRvcl9pZCI6IjIzNjIyNjgyNjQxMTk0NDQ5NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace33ad276b30a2b74738d64ddc903b918ccd060f364e309a76e7db533b7b82ae8
hovercard-subject-tagissue:360463691
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/27103/issue_layout
twitter:imagehttps://opengraph.githubassets.com/bb7787c4bc3917408fe09b0b2876bf2c943a78da6ad77caa9bfdc65e71134f6f/microsoft/TypeScript/issues/27103
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/bb7787c4bc3917408fe09b0b2876bf2c943a78da6ad77caa9bfdc65e71134f6f/microsoft/TypeScript/issues/27103
og:image:altTypeScript Version: latest Search Terms: n/a Code function f(a?: {}) { if (!a) { // filters out falsy values: // - `null` // - `undefined` // - `false` // - `NaN` // - `0` / `-0` // - `''` return {...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameljharb
hostnamegithub.com
expected-hostnamegithub.com
None188497a0f45a7aa8f7c866faa1950d1a7f8d82b59416adf549b222ad1d1dd19b
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
release557cfbac6cdb532730c95c90f2cefdc0c4128029
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/27103#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F27103
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%2F27103
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/27103
Reloadhttps://github.com/microsoft/TypeScript/issues/27103
Reloadhttps://github.com/microsoft/TypeScript/issues/27103
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests318 (318)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/27103
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/27103
Type narrowed to never, incorrectlyhttps://github.com/microsoft/TypeScript/issues/27103#top
Duplicatehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/ljharb
Jordan Harband (ljharb)https://github.com/ljharb
on Sep 14, 2018https://github.com/microsoft/TypeScript/issues/27103#issue-360463691
linkhttp://www.typescriptlang.org/play/#src=function%20f(a%3F%3A%20%7B%7D)%20%7B%0A%20%20%20%20if%20(!a)%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20filters%20out%20falsy%20values%3A%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60null%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60undefined%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60false%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60NaN%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%600%60%20%2F%20%60-0%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20-%20%60''%60%0A%20%20%20%20%20%20%20%20return%20%7B%7D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20here%2C%20the%20type%20of%20%60a%60%20has%20been%20narrowed%20from%20%22optional%20%7B%7D%22%0A%20%20%20%20%2F%2F%20to%20just%20%22%7B%7D%20minus%20%60object%60%22%20(object-coercible%2C%20ie%2C%20anything%20but%20null%2Fundefined%2C%20but%20not%20%60object%60)%0A%20%20%20%20%2F%2F%20effectively%2C%20this%20is%20%60string%20%7C%20number%20%7C%20symbol%20%7C%20boolean%20%7C%20Function%60%0A%0A%20%20%20%20if%20(typeof%20a%20!%3D%3D%20'object')%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20%60a%60%20here%20could%20be%20the%20following%20values%3A%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20function%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20%60true%60%60%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20non-zero%20non-%60NaN%60%60%20number%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20non-empty%20string%0A%20%20%20%20%20%20%20%20%2F%2F%20%20%20-%20a%20symbol%0A%20%20%20%20%20%20%20%20return%20a%3B%20%2F%2F%20however%2C%20the%20type%20inferred%20here%20is%20%60never%60%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20here%2C%20%60a%60%20has%20a%20verifiably%20certain%20type%20of%20%60object%60.%0A%20%20%20%20%2F%2F%20because%20of%20the%20type%20guard%20above.%0A%20%20%20%20return%20a%3B%20%2F%2F%20however%2C%20the%20type%20is%20reported%20as%20%60%7B%7D%60%20%0A%7D
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Sep 14, 2018https://github.com/microsoft/TypeScript/issues/27103#issuecomment-421500094
#18196https://github.com/microsoft/TypeScript/issues/18196
#18196https://github.com/microsoft/TypeScript/issues/18196
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
Duplicatehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
on Sep 14, 2018https://github.com/microsoft/TypeScript/issues/27103#event-1847151350
https://github.com/ljharb
Jordan Harband (ljharb)https://github.com/ljharb
on Sep 18, 2018https://github.com/microsoft/TypeScript/issues/27103#issuecomment-422463841
#27157https://github.com/microsoft/TypeScript/pull/27157
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Dec 14, 2018https://github.com/microsoft/TypeScript/issues/27103#event-2027444476
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Dec 14, 2018https://github.com/microsoft/TypeScript/issues/27103#issuecomment-447403963
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/27103#event-20415797657
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/27103
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/27103
Duplicatehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%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

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.