René's URL Explorer Experiment


Title: Type argument inference for `Extract` too broad (binds all possible keys) · Issue #25065 · microsoft/TypeScript · GitHub

Open Graph Title: Type argument inference for `Extract` too broad (binds all possible keys) · Issue #25065 · microsoft/TypeScript

X Title: Type argument inference for `Extract` too broad (binds all possible keys) · Issue #25065 · microsoft/TypeScript

Description: TypeScript Version: 2.9.2 Search Terms: keyof generic interference In the example below, the calls to getPropertyX(obj, 'first') should bind the type of K as 'first'. However, when the definition of K involves Extract, the inferred bindi...

Open Graph Description: TypeScript Version: 2.9.2 Search Terms: keyof generic interference In the example below, the calls to getPropertyX(obj, 'first') should bind the type of K as 'first'. However, when the definition o...

X Description: TypeScript Version: 2.9.2 Search Terms: keyof generic interference In the example below, the calls to getPropertyX(obj, 'first') should bind the type of K as 'first'. However, when ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type argument inference for `Extract\u003ckey of T, string>` too broad (binds all possible keys)","articleBody":"**TypeScript Version:**  2.9.2\r\n\r\n**Search Terms:** keyof generic interference\r\n\r\nIn the example below, the calls to `getPropertyX(obj, 'first')` should bind the type of K as `'first'`. However, when the definition of K involves `Extract`, the inferred binding is `'first' | 'second'` instead (i.e. all possible keys).\r\n\r\nApropos due to the `keyof` changes in 2.9.\r\n\r\n**Code**\r\n\r\n```ts\r\n// Declaration uses keyof -- no problems\r\nfunction getProperty\u003cT, K extends keyof T>(obj: T, key: K) {\r\n    return obj[key];\r\n}\r\n\r\n// Type argument uses bare keyof, function argument uses Extract (doesn't work)\r\nfunction getProperty2\u003cT, K extends keyof T>(obj: T, key: Extract\u003cK, string>): T[K] {\r\n    return obj[key];\r\n}\r\n\r\n// Type argument uses Extract (doesn't work)\r\nfunction getProperty3\u003cT, K extends Extract\u003ckeyof T, string>>(obj: T, key: K): T[K] {\r\n    return obj[key];\r\n}\r\n\r\n\r\ninterface StrNumPair {\r\n    first: string,\r\n    second: number,\r\n}\r\nconst obj: StrNumPair = {} as any;\r\n\r\nlet prop: string;\r\n\r\n// Works\r\nprop = getProperty(obj, 'first');\r\n\r\n// Doesn't work -- string | number is not assignable to string\r\nprop = getProperty2(obj, 'first');\r\n\r\n// Doesn't work -- string | number is not assignable to string\r\nprop = getProperty3(obj, 'first');\r\n\r\n// Explicit generic binding -- works\r\nprop = getProperty2\u003cStrNumPair, 'first'>(obj, 'first');\r\nprop = getProperty3\u003cStrNumPair, 'first'>(obj, 'first');\r\n```\r\n\r\n**Expected behavior:** K is bound to just the key passed ('first')\r\n\r\n**Actual behavior:** K is bound to all possible keys ('first' | 'second').\r\n\r\n**Playground Link:** http://www.typescriptlang.org/play/#src=%0D%0Afunction%20getProperty%3CT%2C%20K%20extends%20keyof%20T%3E(obj%3A%20T%2C%20key%3A%20K)%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0Afunction%20getProperty2%3CT%2C%20K%20extends%20keyof%20T%3E(obj%3A%20T%2C%20key%3A%20Extract%3CK%2C%20string%3E)%3A%20T%5BK%5D%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0Afunction%20getProperty3%3CT%2C%20K%20extends%20Extract%3Ckeyof%20T%2C%20string%3E%3E(obj%3A%20T%2C%20key%3A%20K)%3A%20T%5BK%5D%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0A%0D%0Ainterface%20StrNumPair%20%7B%0D%0A%20%20%20%20first%3A%20string%2C%0D%0A%20%20%20%20second%3A%20number%2C%0D%0A%7D%0D%0Aconst%20obj%3A%20StrNumPair%20%3D%20%7B%7D%20as%20any%3B%0D%0A%0D%0Alet%20prop%3A%20string%3B%0D%0A%0D%0A%2F%2F%20Works%0D%0Aprop%20%3D%20getProperty(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Doesn't%20work%20--%20string%20%7C%20number%20is%20not%20assignable%20to%20string%0D%0Aprop%20%3D%20getProperty2(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Doesn't%20work%20--%20string%20%7C%20number%20is%20not%20assignable%20to%20string%0D%0Aprop%20%3D%20getProperty3(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Explicit%20generic%20binding%20--%20works%0D%0Aprop%20%3D%20getProperty2%3CStrNumPair%2C%20'first'%3E(obj%2C%20'first')%3B%0D%0Aprop%20%3D%20getProperty3%3CStrNumPair%2C%20'first'%3E(obj%2C%20'first')%3B\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/7sempra","@type":"Person","name":"7sempra"},"datePublished":"2018-06-19T02:34:35Z","url":"https://github.com/microsoft/TypeScript/issues/25065"}

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:edd94935-22db-467c-002b-cf5d4eba6316
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE2DE:19AA62:2164806:2A60400:6B01746A
html-safe-nonce31c97df8656fac979567caf5bbd5d09624c5d25bdffd5eeb719769992f603f22
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkRFOjE5QUE2MjoyMTY0ODA2OjJBNjA0MDA6NkIwMTc0NkEiLCJ2aXNpdG9yX2lkIjoiNjM0ODAwNDc5NTM0NDg0Mzg4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca2a87e4f3f04314571f6b1f5335fdf01f03b2d8da7b4c4d6d96540d7c41e21e2
hovercard-subject-tagissue:333498640
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/25065/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e8d63782d286e13b9521ba18aad5c701616253b8476dcf35c8d5ca9c241e0947/microsoft/TypeScript/issues/25065
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e8d63782d286e13b9521ba18aad5c701616253b8476dcf35c8d5ca9c241e0947/microsoft/TypeScript/issues/25065
og:image:altTypeScript Version: 2.9.2 Search Terms: keyof generic interference In the example below, the calls to getPropertyX(obj, 'first') should bind the type of K as 'first'. However, when the definition o...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:username7sempra
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/25065#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F25065
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%2F25065
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/25065
Reloadhttps://github.com/microsoft/TypeScript/issues/25065
Reloadhttps://github.com/microsoft/TypeScript/issues/25065
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/25065
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/25065
Type argument inference for Extract too broad (binds all possible keys)https://github.com/microsoft/TypeScript/issues/25065#top
https://github.com/weswigham
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
TypeScript 3.1https://github.com/microsoft/TypeScript/milestone/74
https://github.com/7sempra
7semprahttps://github.com/7sempra
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/25065#issue-333498640
http://www.typescriptlang.org/play/#src=%0D%0Afunction%20getProperty%3CT%2C%20K%20extends%20keyof%20T%3E(obj%3A%20T%2C%20key%3A%20K)%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0Afunction%20getProperty2%3CT%2C%20K%20extends%20keyof%20T%3E(obj%3A%20T%2C%20key%3A%20Extract%3CK%2C%20string%3E)%3A%20T%5BK%5D%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0Afunction%20getProperty3%3CT%2C%20K%20extends%20Extract%3Ckeyof%20T%2C%20string%3E%3E(obj%3A%20T%2C%20key%3A%20K)%3A%20T%5BK%5D%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0A%0D%0Ainterface%20StrNumPair%20%7B%0D%0A%20%20%20%20first%3A%20string%2C%0D%0A%20%20%20%20second%3A%20number%2C%0D%0A%7D%0D%0Aconst%20obj%3A%20StrNumPair%20%3D%20%7B%7D%20as%20any%3B%0D%0A%0D%0Alet%20prop%3A%20string%3B%0D%0A%0D%0A%2F%2F%20Works%0D%0Aprop%20%3D%20getProperty(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Doesn't%20work%20--%20string%20%7C%20number%20is%20not%20assignable%20to%20string%0D%0Aprop%20%3D%20getProperty2(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Doesn't%20work%20--%20string%20%7C%20number%20is%20not%20assignable%20to%20string%0D%0Aprop%20%3D%20getProperty3(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Explicit%20generic%20binding%20--%20works%0D%0Aprop%20%3D%20getProperty2%3CStrNumPair%2C%20'first'%3E(obj%2C%20'first')%3B%0D%0Aprop%20%3D%20getProperty3%3CStrNumPair%2C%20'first'%3E(obj%2C%20'first')%3Bhttp://www.typescriptlang.org/play/#src=%0D%0Afunction%20getProperty%3CT%2C%20K%20extends%20keyof%20T%3E(obj%3A%20T%2C%20key%3A%20K)%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0Afunction%20getProperty2%3CT%2C%20K%20extends%20keyof%20T%3E(obj%3A%20T%2C%20key%3A%20Extract%3CK%2C%20string%3E)%3A%20T%5BK%5D%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0Afunction%20getProperty3%3CT%2C%20K%20extends%20Extract%3Ckeyof%20T%2C%20string%3E%3E(obj%3A%20T%2C%20key%3A%20K)%3A%20T%5BK%5D%20%7B%0D%0A%20%20%20%20return%20obj%5Bkey%5D%3B%0D%0A%7D%0D%0A%0D%0A%0D%0Ainterface%20StrNumPair%20%7B%0D%0A%20%20%20%20first%3A%20string%2C%0D%0A%20%20%20%20second%3A%20number%2C%0D%0A%7D%0D%0Aconst%20obj%3A%20StrNumPair%20%3D%20%7B%7D%20as%20any%3B%0D%0A%0D%0Alet%20prop%3A%20string%3B%0D%0A%0D%0A%2F%2F%20Works%0D%0Aprop%20%3D%20getProperty(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Doesn't%20work%20--%20string%20%7C%20number%20is%20not%20assignable%20to%20string%0D%0Aprop%20%3D%20getProperty2(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Doesn't%20work%20--%20string%20%7C%20number%20is%20not%20assignable%20to%20string%0D%0Aprop%20%3D%20getProperty3(obj%2C%20'first')%3B%0D%0A%0D%0A%2F%2F%20Explicit%20generic%20binding%20--%20works%0D%0Aprop%20%3D%20getProperty2%3CStrNumPair%2C%20'first'%3E(obj%2C%20'first')%3B%0D%0Aprop%20%3D%20getProperty3%3CStrNumPair%2C%20'first'%3E(obj%2C%20'first')%3B
https://github.com/s-ve
s-vehttps://github.com/s-ve
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/25065#issuecomment-398454680
#24560https://github.com/microsoft/TypeScript/issues/24560
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/25065#event-1689120953
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Wesley Wigham (weswigham)https://github.com/weswigham
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/25065#event-1689121037
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
TypeScript 3.0https://github.com/microsoft/TypeScript/milestone/70
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/25065#event-1689121128
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
TypeScript 3.0https://github.com/microsoft/TypeScript/milestone/70
TypeScript 3.1https://github.com/microsoft/TypeScript/milestone/74
on Jul 2, 2018https://github.com/microsoft/TypeScript/issues/25065#event-1712727882
Wesley Wigham (weswigham)https://github.com/weswigham
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#27012https://github.com/microsoft/TypeScript/pull/27012
on Sep 17, 2018https://github.com/microsoft/TypeScript/issues/25065#event-1850978484
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/25065#event-20415708353
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/25065
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/25065
Wesley Wigham (weswigham)https://github.com/weswigham
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
TypeScript 3.1https://github.com/microsoft/TypeScript/milestone/74
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.