René's URL Explorer Experiment


Title: Compile Error when using generic type with `[K in keyof T]?: XXX` · Issue #31070 · microsoft/TypeScript · GitHub

Open Graph Title: Compile Error when using generic type with `[K in keyof T]?: XXX` · Issue #31070 · microsoft/TypeScript

X Title: Compile Error when using generic type with `[K in keyof T]?: XXX` · Issue #31070 · microsoft/TypeScript

Description: TypeScript Version: 3.4.4 Search Terms: keyof index-properties generic-type Code type Numeric = { [K in keyof T]?: number } class Entity { aNumber: number; } const fn = () => { const n: Numeric = { // . ^ // . Typ...

Open Graph Description: TypeScript Version: 3.4.4 Search Terms: keyof index-properties generic-type Code type Numeric = { [K in keyof T]?: number } class Entity { aNumber: number; } const fn = () => {...

X Description: TypeScript Version: 3.4.4 Search Terms: keyof index-properties generic-type Code type Numeric<T> = { [K in keyof T]?: number } class Entity { aNumber: number; } const fn = <T extends Entit...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Compile Error when using generic type with `[K in keyof T]?: XXX` ","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  3.4.4\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\nkeyof index-properties generic-type\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Numeric\u003cT> = {\r\n    [K in keyof T]?: number\r\n}\r\n\r\nclass Entity {\r\n    aNumber: number;\r\n}\r\n\r\nconst fn = \u003cT extends Entity>() => {\r\n    const n: Numeric\u003cT> = {\r\n// .      ^\r\n// .      Type '{ aNumber: number; }' is not assignable to type 'Numeric\u003cT>'\r\n        aNumber: 1\r\n    };\r\n};\r\n```\r\n\r\n**Expected behavior:**\r\nShould not report compile error since in the type constraint of function `fn` was `\u003cT extends Entity>` which means `T` should have `aNumber: number` and `{ aNumber: 1 }` should be satisfied.\r\n\r\n**Actual behavior:**\r\nCompile error said `Type '{ aNumber: number; }' is not assignable to type 'Numeric\u003cT>'`.\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\nhttps://www.typescriptlang.org/play/index.html#src=type%20Numeric%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BK%20in%20keyof%20T%5D%3F%3A%20number%0D%0A%7D%0D%0A%0D%0Aclass%20Entity%20%7B%0D%0A%20%20%20%20aNumber%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Aconst%20fn%20%3D%20%3CT%20extends%20Entity%3E()%20%3D%3E%20%7B%0D%0A%20%20%20%20const%20n%3A%20Numeric%3CT%3E%20%3D%20%7B%0D%0A%2F%2F%20.%20%20%20%20%20%20%5E%0D%0A%2F%2F%20.%20%20%20%20%20%20Type%20'%7B%20aNumber%3A%20number%3B%20%7D'%20is%20not%20assignable%20to%20type%20'Numeric%3CT%3E'%0D%0A%20%20%20%20%20%20%20%20aNumber%3A%201%0D%0A%20%20%20%20%7D%3B%0D%0A%7D%3B\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\nhttps://stackoverflow.com/questions/55804034/keyof-reported-compile-error-when-using-generic-type","author":{"url":"https://github.com/shaunxu","@type":"Person","name":"shaunxu"},"datePublished":"2019-04-23T06:12:00Z","url":"https://github.com/microsoft/TypeScript/issues/31070"}

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:bb1bf5be-454e-ac0a-e866-0bd8e0a2f4d1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA5A0:2A5566:E5D37E:12E0089:6B01CDD1
html-safe-nonce44e9f0e4e0115ae0208459685cd88d3066f708ca9467e393fa47dac03ce8b7d6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUEwOjJBNTU2NjpFNUQzN0U6MTJFMDA4OTo2QjAxQ0REMSIsInZpc2l0b3JfaWQiOiI4MjY3NzE0ODEyODMwNjY2MTk0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac816c7e1a15f25b21185de752b124b73ce2f25532f31b399deee5084bfaf77a87
hovercard-subject-tagissue:436015005
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/31070/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9a40e25889c54799aa3300e10f479bf249192533e45b1b0a632a0f1686e95165/microsoft/TypeScript/issues/31070
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9a40e25889c54799aa3300e10f479bf249192533e45b1b0a632a0f1686e95165/microsoft/TypeScript/issues/31070
og:image:altTypeScript Version: 3.4.4 Search Terms: keyof index-properties generic-type Code type Numeric = { [K in keyof T]?: number } class Entity { aNumber: number; } const fn = () => {...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameshaunxu
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/31070#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F31070
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%2F31070
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/31070
Reloadhttps://github.com/microsoft/TypeScript/issues/31070
Reloadhttps://github.com/microsoft/TypeScript/issues/31070
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/31070
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31070
#32071https://github.com/microsoft/TypeScript/pull/32071
Compile Error when using generic type with [K in keyof T]?: XXX https://github.com/microsoft/TypeScript/issues/31070#top
#32071https://github.com/microsoft/TypeScript/pull/32071
https://github.com/andrewbranch
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: Mapped TypesThe issue relates to mapped typeshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20Mapped%20Types%22
TypeScript 3.6.0https://github.com/microsoft/TypeScript/milestone/93
https://github.com/shaunxu
Shaun Xu (shaunxu)https://github.com/shaunxu
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issue-436015005
https://www.typescriptlang.org/play/index.html#src=type%20Numeric%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BK%20in%20keyof%20T%5D%3F%3A%20number%0D%0A%7D%0D%0A%0D%0Aclass%20Entity%20%7B%0D%0A%20%20%20%20aNumber%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Aconst%20fn%20%3D%20%3CT%20extends%20Entity%3E()%20%3D%3E%20%7B%0D%0A%20%20%20%20const%20n%3A%20Numeric%3CT%3E%20%3D%20%7B%0D%0A%2F%2F%20.%20%20%20%20%20%20%5E%0D%0A%2F%2F%20.%20%20%20%20%20%20Type%20'%7B%20aNumber%3A%20number%3B%20%7D'%20is%20not%20assignable%20to%20type%20'Numeric%3CT%3E'%0D%0A%20%20%20%20%20%20%20%20aNumber%3A%201%0D%0A%20%20%20%20%7D%3B%0D%0A%7D%3Bhttps://www.typescriptlang.org/play/index.html#src=type%20Numeric%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BK%20in%20keyof%20T%5D%3F%3A%20number%0D%0A%7D%0D%0A%0D%0Aclass%20Entity%20%7B%0D%0A%20%20%20%20aNumber%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Aconst%20fn%20%3D%20%3CT%20extends%20Entity%3E()%20%3D%3E%20%7B%0D%0A%20%20%20%20const%20n%3A%20Numeric%3CT%3E%20%3D%20%7B%0D%0A%2F%2F%20.%20%20%20%20%20%20%5E%0D%0A%2F%2F%20.%20%20%20%20%20%20Type%20'%7B%20aNumber%3A%20number%3B%20%7D'%20is%20not%20assignable%20to%20type%20'Numeric%3CT%3E'%0D%0A%20%20%20%20%20%20%20%20aNumber%3A%201%0D%0A%20%20%20%20%7D%3B%0D%0A%7D%3B
https://stackoverflow.com/questions/55804034/keyof-reported-compile-error-when-using-generic-typehttps://stackoverflow.com/questions/55804034/keyof-reported-compile-error-when-using-generic-type
https://github.com/barld
Barld Boot (barld)https://github.com/barld
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-485691557
https://github.com/shaunxu
Shaun Xu (shaunxu)https://github.com/shaunxu
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-485716344
https://github.com/jack-williams
Jack Williams (jack-williams)https://github.com/jack-williams
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-485789352
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-485875881
#13442https://github.com/microsoft/TypeScript/issues/13442
https://github.com/hackape
hackapehttps://github.com/hackape
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-485882425
Joe Calzaretta (@jcalz)https://github.com/jcalz
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Apr 23, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-485895111
#13442https://github.com/microsoft/TypeScript/issues/13442
https://github.com/shaunxu
Shaun Xu (shaunxu)https://github.com/shaunxu
on Apr 25, 2019https://github.com/microsoft/TypeScript/issues/31070#issuecomment-486494263
Jack Williams (@jack-williams)https://github.com/jack-williams
Wesley Wigham (weswigham)https://github.com/weswigham
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: Mapped TypesThe issue relates to mapped typeshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20Mapped%20Types%22
on May 8, 2019https://github.com/microsoft/TypeScript/issues/31070#event-2327945983
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Andrew Branch (andrewbranch)https://github.com/andrewbranch
on Jun 12, 2019https://github.com/microsoft/TypeScript/issues/31070#event-2408221053
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.6.0https://github.com/microsoft/TypeScript/milestone/93
on Jun 12, 2019https://github.com/microsoft/TypeScript/issues/31070#event-2408221121
Andrew Branch (andrewbranch)https://github.com/andrewbranch
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#32071https://github.com/microsoft/TypeScript/pull/32071
on Jul 1, 2019https://github.com/microsoft/TypeScript/issues/31070#event-2452334317
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/31070#event-20416663349
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/31070
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31070
Andrew Branch (andrewbranch)https://github.com/andrewbranch
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: Mapped TypesThe issue relates to mapped typeshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20Mapped%20Types%22
TypeScript 3.6.0https://github.com/microsoft/TypeScript/milestone/93
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.