René's URL Explorer Experiment


Title: Storing a keyof to a string quoted number key produces TS2344: invalid constraint in declaration file · Issue #37292 · microsoft/TypeScript · GitHub

Open Graph Title: Storing a keyof to a string quoted number key produces TS2344: invalid constraint in declaration file · Issue #37292 · microsoft/TypeScript

X Title: Storing a keyof to a string quoted number key produces TS2344: invalid constraint in declaration file · Issue #37292 · microsoft/TypeScript

Description: TypeScript Version: 3.8.3 and 3.9.0-dev.20200309 Search Terms: [keyof quote], [keyof number declaration], [key number], [key quote], [object key number declaration] Code // test.ts class C { readonly lines = { '1': 'abc', '2a': 'def' } }...

Open Graph Description: TypeScript Version: 3.8.3 and 3.9.0-dev.20200309 Search Terms: [keyof quote], [keyof number declaration], [key number], [key quote], [object key number declaration] Code // test.ts class C { readon...

X Description: TypeScript Version: 3.8.3 and 3.9.0-dev.20200309 Search Terms: [keyof quote], [keyof number declaration], [key number], [key quote], [object key number declaration] Code // test.ts class C { readon...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Storing a keyof to a string quoted number key produces TS2344: invalid constraint in declaration file","articleBody":"**TypeScript Version:**  3.8.3 and 3.9.0-dev.20200309\r\n\r\n**Search Terms:** [keyof quote], [keyof number declaration], [key number], [key quote], [object key number declaration]\r\n\r\n**Code**\r\n\r\n```ts\r\n// test.ts\r\nclass C {\r\n    readonly lines = {\r\n        '1': 'abc',\r\n        '2a': 'def'\r\n    }\r\n}\r\n\r\nclass Ref\u003cT extends keyof C['lines']> {\r\n    private _key: T;\r\n    private _c = new C();\r\n\r\n    constructor(key: T) {\r\n        this._key = key;\r\n    }\r\n\r\n    value(): C['lines'][T] {\r\n        return this._c.lines[this._key];\r\n    }\r\n}\r\n\r\nconst r1 = new Ref('1');\r\nconst r2 = new Ref('2a');\r\n```\r\n\r\n**Expected behavior:**\r\n1. Run `tsc --declaration test.ts`\r\n2. Run `npx tsc --noEmit test.d.ts`\r\n3. No error is emitted\r\n\r\n**Actual behavior:**\r\nStep (2) actually produces an error:\r\n\r\n2. Run `npx tsc --noEmit test.d.ts`\r\n```\r\ntest.d.ts:13:23 - error TS2344: Type '\"1\"' does not satisfy the constraint '1 | \"2a\"'.\r\n\r\n13 declare const r1: Ref\u003c\"1\">;\r\n```\r\n\r\nWhen examining the output, note the two lines marked \"BUG\": the key in the `lines` object for `1` has been converted to number, but the `Ref\u003c\"1\">` is trying to access the key as a string.\r\n\r\n```ts\r\n// test.d.ts\r\ndeclare class C {\r\n    readonly lines: {\r\n        1: string;     // BUG\r\n        '2a': string;\r\n    };\r\n}\r\ndeclare class Ref\u003cT extends keyof C['lines']> {\r\n    private _key;\r\n    private _c;\r\n    constructor(key: T);\r\n    value(): C['lines'][T];\r\n}\r\ndeclare const r1: Ref\u003c\"1\">;   // BUG\r\ndeclare const r2: Ref\u003c\"2a\">;\r\n```\r\n\r\nWhen tsc un-quotes the numeric key in `C`'s definition, the `Ref\u003c\"1\">` produces a type mismatch.\r\n\r\n**Playground Link:** [Playground Link](https://www.typescriptlang.org/play/index.html?ssl=1&ssc=1&pln=23&pc=1#code/MYGwhgzhAEDC0G8BQ1XQE4FMwBMD2AdiAJ7QgCWBmMAvIimowOQCMTAXNE2AEbBMAaBo1RMATGA5ccmAGZNh0AL5IVSUJBgAlOQB4AKtEwAPAC6YCOGAGtMxPLLgBtJhSoQmAXQB89RgAd0cgA3MHNoAH1bYk59AG5FQJCwzEjgaDoqAHc4AAoASgTFYEIIU3QAV2BTPHRc6Nj8vxFUUwALcggAOii7DOhohMY1RlCQCswCzlgXN2ovJ31PZpasUwr0Amh2zp7gLrmIJx3u3uJPIbQVNRKCMowWfuzoHVlc1iZC9VLTDDEnzA5V7vCSfBJAA)\r\n\r\n**Related Issues:** \r\n- #36852\r\n- #20602\r\n","author":{"url":"https://github.com/rsesek","@type":"Person","name":"rsesek"},"datePublished":"2020-03-09T13:55:48Z","url":"https://github.com/microsoft/TypeScript/issues/37292"}

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:187c5a67-0950-59a4-a1c7-ebde7dd6752c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA298:17FB7:1E0A928:2611719:6B019C05
html-safe-nonce0ef047682ee1b0b13461449f72c61f2f7dbe0fa0abef54fe8e6bb3b6de89154e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjk4OjE3RkI3OjFFMEE5Mjg6MjYxMTcxOTo2QjAxOUMwNSIsInZpc2l0b3JfaWQiOiI3OTU1OTMxNTA2MDQyNTc1ODc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac2f4cfdeb8250e45f1b80efc876a861e3f276d89c6fc5f1083db30b932ed8564c
hovercard-subject-tagissue:577927324
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/37292/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2ed1554e85612e7c8ca465ef28fa64d139ef691b808cd57664e1c9ea5a76e81b/microsoft/TypeScript/issues/37292
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2ed1554e85612e7c8ca465ef28fa64d139ef691b808cd57664e1c9ea5a76e81b/microsoft/TypeScript/issues/37292
og:image:altTypeScript Version: 3.8.3 and 3.9.0-dev.20200309 Search Terms: [keyof quote], [keyof number declaration], [key number], [key quote], [object key number declaration] Code // test.ts class C { readon...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamersesek
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/37292#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F37292
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%2F37292
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/37292
Reloadhttps://github.com/microsoft/TypeScript/issues/37292
Reloadhttps://github.com/microsoft/TypeScript/issues/37292
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/37292
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/37292
#39658https://github.com/microsoft/TypeScript/pull/39658
Storing a keyof to a string quoted number key produces TS2344: invalid constraint in declaration filehttps://github.com/microsoft/TypeScript/issues/37292#top
#39658https://github.com/microsoft/TypeScript/pull/39658
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.0.1https://github.com/microsoft/TypeScript/milestone/123
https://github.com/rsesek
Robert Sesek (rsesek)https://github.com/rsesek
on Mar 9, 2020https://github.com/microsoft/TypeScript/issues/37292#issue-577927324
Playground Linkhttps://www.typescriptlang.org/play/index.html?ssl=1&ssc=1&pln=23&pc=1#code/MYGwhgzhAEDC0G8BQ1XQE4FMwBMD2AdiAJ7QgCWBmMAvIimowOQCMTAXNE2AEbBMAaBo1RMATGA5ccmAGZNh0AL5IVSUJBgAlOQB4AKtEwAPAC6YCOGAGtMxPLLgBtJhSoQmAXQB89RgAd0cgA3MHNoAH1bYk59AG5FQJCwzEjgaDoqAHc4AAoASgTFYEIIU3QAV2BTPHRc6Nj8vxFUUwALcggAOii7DOhohMY1RlCQCswCzlgXN2ovJ31PZpasUwr0Amh2zp7gLrmIJx3u3uJPIbQVNRKCMowWfuzoHVlc1iZC9VLTDDEnzA5V7vCSfBJAA
Generic constraint generates a TS2344  #36852https://github.com/microsoft/TypeScript/issues/36852
keyof has different literal type behavior when used in function signature #20602https://github.com/microsoft/TypeScript/issues/20602
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3121618856
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Wesley Wigham (weswigham)https://github.com/weswigham
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3121618929
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 4.0https://github.com/microsoft/TypeScript/milestone/114
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3121619096
https://github.com/a-tarasyuk
Oleksandr Tarasiuk (a-tarasyuk)https://github.com/a-tarasyuk
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#issuecomment-598128566
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
Wesley Wigham (@weswigham)https://github.com/weswigham
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Wesley Wigham (weswigham)https://github.com/weswigham
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3124474989
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 4.0https://github.com/microsoft/TypeScript/milestone/114
Backloghttps://github.com/microsoft/TypeScript/milestone/29
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3124476638
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#issuecomment-598425802
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 12, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3124567739
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jul 16, 2020https://github.com/microsoft/TypeScript/issues/37292#issuecomment-659133902
https://github.com/weswigham
Wesley Wigham (weswigham)https://github.com/weswigham
on Jul 16, 2020https://github.com/microsoft/TypeScript/issues/37292#issuecomment-659143314
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jul 16, 2020https://github.com/microsoft/TypeScript/issues/37292#issuecomment-659559167
Wesley Wigham (@weswigham)https://github.com/weswigham
#39101https://github.com/microsoft/TypeScript/pull/39101
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jul 18, 2020https://github.com/microsoft/TypeScript/issues/37292#issuecomment-660552329
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
on Jul 19, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3561831808
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Backloghttps://github.com/microsoft/TypeScript/milestone/29
TypeScript 4.0.1https://github.com/microsoft/TypeScript/milestone/123
on Jul 19, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3561831988
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#39658https://github.com/microsoft/TypeScript/pull/39658
on Jul 20, 2020https://github.com/microsoft/TypeScript/issues/37292#event-3567027017
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/37292#event-20416903930
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/37292
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/37292
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.0.1https://github.com/microsoft/TypeScript/milestone/123
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.