René's URL Explorer Experiment


Title: Can't call `((_: string) => T) | undefined` when conditionally `string extends T` · Issue #43425 · microsoft/TypeScript · GitHub

Open Graph Title: Can't call `((_: string) => T) | undefined` when conditionally `string extends T` · Issue #43425 · microsoft/TypeScript

X Title: Can't call `((_: string) => T) | undefined` when conditionally `string extends T` · Issue #43425 · microsoft/TypeScript

Description: Bug Report I am trying to make a generic callback function (_: string) => T, that is allowed to be optional (undefined) only when T is string. (Specifically, I chose string extends T because TS doesn't seem to provide exact equality for ...

Open Graph Description: Bug Report I am trying to make a generic callback function (_: string) => T, that is allowed to be optional (undefined) only when T is string. (Specifically, I chose string extends T because TS doe...

X Description: Bug Report I am trying to make a generic callback function (_: string) => T, that is allowed to be optional (undefined) only when T is string. (Specifically, I chose string extends T because TS ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can't call `((_: string) => T) | undefined` when conditionally `string extends T`","articleBody":"# Bug Report\r\n\r\nI am trying to make a generic callback function `(_: string) => T`, that is allowed to be optional (undefined) only when `T` is `string`. (Specifically, I chose `string extends T` because TS doesn't seem to provide exact equality for conditional types, and I want the default value to be `(x: string) => x`.)\r\n\r\nThe initial way I wrote this was `string extends T ? ((value: string) => T) | undefined : (value: string) => T`, but I found I was unable to (conditionally) call the function. The error seems to stem from TS treating the type as `(value: T & string) => T`, which prevent me from passing in a string literal.\r\n\r\n\u003cimg width=\"590\" alt=\"image\" src=\"https://user-images.githubusercontent.com/14237/112906752-66d32e00-9088-11eb-8109-75a996f84630.png\">\r\n\r\nI found a workaround that allows me to call the function: `((value: string) => T) | (string extends T ? undefined : never)` (**which I believe should be exactly equivalent**, though let me know if this is wrong). However, this too is broken in the latest nightly, seemingly because of how `NonNullable` is being distributed over `|`:\r\n\r\n\u003cimg width=\"607\" alt=\"Screen Shot 2021-03-29 at 12 17 07 PM\" src=\"https://user-images.githubusercontent.com/14237/112906960-c4677a80-9088-11eb-913f-f007ca22b972.png\">\r\n\r\n\r\n### 🔎 Search Terms\r\n\r\ngeneric extends function parameter union 🤷\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 3.8.3 and 3.9.7, and changed again between 4.2.2 and the nightly.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?#code/C4TwDgpgBAKgTgQwHYGcBmB7OBbAjAHhgD4oBeKACgoDcEAbAVwgC4oVg4BLJAcwEoyJGAIA+ldl15QIAD2AQkAExSwoAfigMlENNwiKorJBGoQ4fANwBYAFChIsRKkw4ATIRLkJ3HtLkLlVQ0qWkYWNg4fAVIhUU1tXWMDVhp6JlZvXmihaxtbNC0AY2BODCQoeXYPCjRcVnhkdCw8DwAaKDRXeqcmtw8BAG9bKA7cNQA6CgAiAAsIOjoMKcthjtcJ6bmFpZWbAF9bIA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype Transform1\u003cT> = ((value: string) => T) | (string extends T ? undefined : never);\r\ntype Transform2\u003cT> = string extends T ? ((value: string) => T) | undefined : (value: string) => T;\r\n\r\nfunction test\u003cT>(f1: Transform1\u003cT>, f2: Transform2\u003cT>) {\r\n  f1?.(\"hello\");  // error in nightly, no error in 4.2.2\r\n  f2?.(\"hello\");  // error since 3.9.7, no error in 3.8.3\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nError on the call to `f1` in 4.2.2, and errors on both calls in the nightly.\r\n\r\n### 🙂 Expected behavior\r\n\r\nBoth calls should succeed. The function return value is ignored, so `string extends T` should have no impact on the validity of the expression.\r\n","author":{"url":"https://github.com/jtbandes","@type":"Person","name":"jtbandes"},"datePublished":"2021-03-29T22:21:19Z","url":"https://github.com/microsoft/TypeScript/issues/43425"}

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:59f08402-cf52-48d9-097f-181f4ef16593
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD5D0:B1B84:19496A0:201A2FA:6B01839E
html-safe-noncea0bce14819f0448feeefb5569f1a19104f5758dd4bc5a8eaf4ac4e0ddcad89fa
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUQwOkIxQjg0OjE5NDk2QTA6MjAxQTJGQTo2QjAxODM5RSIsInZpc2l0b3JfaWQiOiI1NDUwNDU1MTgyODAwNDIxNzkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac143d05e49d56f10481de6d3d1b8a23620ada37736b5b2b481a7c8bdb6d082c7b
hovercard-subject-tagissue:843863328
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/43425/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e3e25e1674d462df7818d78383d10f22566ad5a6667b56b72a03a930e03a4662/microsoft/TypeScript/issues/43425
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e3e25e1674d462df7818d78383d10f22566ad5a6667b56b72a03a930e03a4662/microsoft/TypeScript/issues/43425
og:image:altBug Report I am trying to make a generic callback function (_: string) => T, that is allowed to be optional (undefined) only when T is string. (Specifically, I chose string extends T because TS doe...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejtbandes
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/43425#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F43425
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%2F43425
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/43425
Reloadhttps://github.com/microsoft/TypeScript/issues/43425
Reloadhttps://github.com/microsoft/TypeScript/issues/43425
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/43425
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43425
#44219https://github.com/microsoft/TypeScript/pull/44219
Can't call ((_: string) => T) | undefined when conditionally string extends Thttps://github.com/microsoft/TypeScript/issues/43425#top
#44219https://github.com/microsoft/TypeScript/pull/44219
https://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
TypeScript 4.3.1https://github.com/microsoft/TypeScript/milestone/138
https://github.com/jtbandes
Jacob Bandes-Storch (jtbandes)https://github.com/jtbandes
on Mar 29, 2021https://github.com/microsoft/TypeScript/issues/43425#issue-843863328
https://user-images.githubusercontent.com/14237/112906752-66d32e00-9088-11eb-8109-75a996f84630.png
https://user-images.githubusercontent.com/14237/112906960-c4677a80-9088-11eb-913f-f007ca22b972.png
Playground link with relevant codehttps://www.typescriptlang.org/play#code/C4TwDgpgBAKgTgQwHYGcBmB7OBbAjAHhgD4oBeKACgoDcEAbAVwgC4oVg4BLJAcwEoyJGAIA+ldl15QIAD2AQkAExSwoAfigMlENNwiKorJBGoQ4fANwBYAFChIsRKkw4ATIRLkJ3HtLkLlVQ0qWkYWNg4fAVIhUU1tXWMDVhp6JlZvXmihaxtbNC0AY2BODCQoeXYPCjRcVnhkdCw8DwAaKDRXeqcmtw8BAG9bKA7cNQA6CgAiAAsIOjoMKcthjtcJ6bmFpZWbAF9bIA
https://github.com/jtbandes
Jacob Bandes-Storch (jtbandes)https://github.com/jtbandes
on Mar 29, 2021https://github.com/microsoft/TypeScript/issues/43425#issuecomment-809767265
the return type of my default function can't be treated as compatible with Thttps://www.typescriptlang.org/play#code/C4TwDgpgBAKgTgQwHYGcBmB7OBbAjAHhgD4oBeKACgoDcEAbAVwgC4oVg4BLJAcwEoyJGAIA+ldl15QIAD2AQkAExSwoAfigMlENNwiKorJBGoQ4fANwBYAFChIsRKkw4ATIRLkJ3HtLkLlVQ0qWkYWNg4fAVIhUU1tXWMDVhp6JlZvXmihaxtbAGMMVGAoRR0EBjpgeGR0LGwyShkMyKzBKBlc2zQtfOBOIqh5dg8KCRbJHgAaKDRcVhrneoJiGbRXBac6tw8BAG9bKCg6CBK4CBRK4HnVcgo59Q0ytAqqxe3sPjGOS0Pj06g50uVQ2t0o60epXKV3eLk+33MuQAvrYgA
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 30, 2021https://github.com/microsoft/TypeScript/issues/43425#issuecomment-810398050
#43427https://github.com/microsoft/TypeScript/issues/43427
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 30, 2021https://github.com/microsoft/TypeScript/issues/43425#issuecomment-810398749
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Needs InvestigationThis issue needs a team member to investigate its status.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Investigation%22
on Mar 30, 2021https://github.com/microsoft/TypeScript/issues/43425#event-4528886726
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Mar 30, 2021https://github.com/microsoft/TypeScript/issues/43425#event-4528887047
https://github.com/jtbandes
Jacob Bandes-Storch (jtbandes)https://github.com/jtbandes
on Apr 3, 2021https://github.com/microsoft/TypeScript/issues/43425#issuecomment-812926857
15fae38https://github.com/microsoft/TypeScript/commit/15fae38b39a370f1f597606e552dd40998a1ac49
#43183https://github.com/microsoft/TypeScript/pull/43183
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Needs InvestigationThis issue needs a team member to investigate its status.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Investigation%22
on May 22, 2021https://github.com/microsoft/TypeScript/issues/43425#event-4782449198
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
TypeScript 4.3.1https://github.com/microsoft/TypeScript/milestone/138
on May 22, 2021https://github.com/microsoft/TypeScript/issues/43425#event-4782449404
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on May 22, 2021https://github.com/microsoft/TypeScript/issues/43425#issuecomment-846424950
#43183https://github.com/microsoft/TypeScript/pull/43183
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
on May 23, 2021https://github.com/microsoft/TypeScript/issues/43425#event-4782840356
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#44219https://github.com/microsoft/TypeScript/pull/44219
on May 25, 2021https://github.com/microsoft/TypeScript/issues/43425#event-4794553112
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/43425#event-20417390209
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/43425
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43425
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
TypeScript 4.3.1https://github.com/microsoft/TypeScript/milestone/138
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.