René's URL Explorer Experiment


Title: False-positive errors regarding string array const · Issue #52684 · microsoft/TypeScript · GitHub

Open Graph Title: False-positive errors regarding string array const · Issue #52684 · microsoft/TypeScript

X Title: False-positive errors regarding string array const · Issue #52684 · microsoft/TypeScript

Description: Bug Report 🕗 Version & Regression Information It's not a regression, the same behaviour can be observed on TS 4 and 5. (for TS 4, using ts-toolbelt's Narrow function gives equivalent results) 💻 Code const staticPath1Level = ["home"] as c...

Open Graph Description: Bug Report 🕗 Version & Regression Information It's not a regression, the same behaviour can be observed on TS 4 and 5. (for TS 4, using ts-toolbelt's Narrow function gives equivalent results) 💻 Cod...

X Description: Bug Report 🕗 Version & Regression Information It's not a regression, the same behaviour can be observed on TS 4 and 5. (for TS 4, using ts-toolbelt's Narrow function gives equivalent re...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False-positive errors regarding string array const","articleBody":"# Bug Report\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nIt's not a regression, the same behaviour can be observed on TS 4 and 5. (for TS 4, using [ts-toolbelt](https://github.com/millsp/ts-toolbelt)'s Narrow function gives equivalent results)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nconst staticPath1Level = [\"home\"] as const;\r\nconst staticPath2Level = [\"home\", \"user\"] as const;\r\nconst staticPath3Level = [\"home\", \"user\", \"downloads\"] as const;\r\n\r\nconst randomID = 'id' as string;\r\n\r\n// TS 5\r\ndeclare function foo\u003cconst T extends string[] | readonly string[]>(path: T): T;\r\n// TS 4\r\n// declare function foo\u003cT extends string[] | readonly string[]>(path: F.Narrow\u003cT>): T;\r\n\r\nconst a1 = foo([...staticPath1Level, randomID, 'doc.pdf']);\r\nconst a2 = foo([...staticPath2Level, randomID, 'doc.pdf']);\r\nconst a3 = foo([...staticPath3Level, randomID, 'doc.pdf']);\r\n\r\nconst b1 = foo([...staticPath1Level, randomID, 'folder', 'doc.pdf']);\r\nconst b2 = foo([...staticPath2Level, randomID, 'folder', 'doc.pdf']);\r\nconst b3 = foo([...staticPath3Level, randomID, 'folder', 'doc.pdf']);\r\n\r\nconst c1 = foo([...staticPath1Level, randomID, 'folder', 'subfolder', 'doc.pdf']);\r\nconst c2 = foo([...staticPath2Level, randomID, 'folder', 'subfolder', 'doc.pdf']);\r\nconst c3 = foo([...staticPath3Level, randomID, 'folder', 'subfolder', 'doc.pdf']);\r\n\r\nconst d1 = foo([...staticPath1Level, randomID, 'folder', 'subfolder', 'another-subfolder', 'doc.pdf']);\r\nconst d2 = foo([...staticPath2Level, randomID, 'folder', 'subfolder', 'another-subfolder', 'doc.pdf']);\r\nconst d3 = foo([...staticPath3Level, randomID, 'folder', 'subfolder', 'another-subfolder', 'doc.pdf']);\r\n\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nAll return types are correct, e.g.:\r\n```ts\r\nconst b3: readonly [\"home\", \"user\", \"downloads\", string, \"folder\", \"doc.pdf\"]\r\n```\r\n\r\nThe call for a2 has the following error (b3, c3 also have the same error type, adjusted for their parameters):\r\n> ts(2345)\r\n> Argument of type '[\"home\", \"user\", string, string]' is not assignable to parameter of type 'readonly [\"home\", \"user\", string, \"doc.pdf\"]'.\r\n>  Type at position 3 in source is not compatible with type at position 3 in target.\r\n>    Type 'string' is not assignable to type '\"doc.pdf\"'.\r\n\r\nThe call for b2 has the following error (c2, d2, d3 also have the same error type, adjusted for their parameters):\r\n> ts(2322)\r\n> Type 'string' is not assignable to type '\"folder\"'.\r\n\r\n\r\n### 🙂 Expected behavior\r\n\r\nDon't generate false-positive errors. Also, it's odd that there is no apparent pattern to when one of the errors is shown.\r\n\r\n### Workaround\r\n\r\nTo silence these errors, `as const` can be used, but again, it's not really obvious where or how many times.\r\nThis partial code sample generates no errors:\r\n```ts\r\nconst b2 = foo([...staticPath2Level, randomID, 'folder' as const, 'doc.pdf']);\r\nconst b3 = foo([...staticPath3Level, randomID, 'folder', 'doc.pdf' as const]);\r\n```\r\nThis partial code sample still has false-positive errors:\r\n```ts\r\nconst b2 = foo([...staticPath2Level, randomID, 'folder', 'doc.pdf' as const]);\r\nconst b3 = foo([...staticPath3Level, randomID, 'folder' as const, 'doc.pdf']);\r\n```","author":{"url":"https://github.com/mocanew","@type":"Person","name":"mocanew"},"datePublished":"2023-02-08T18:25:56Z","url":"https://github.com/microsoft/TypeScript/issues/52684"}

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:1f3bac77-a8df-4b58-9ab7-cfeaad47e986
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAB22:24A0A:1D700CB:25276A9:6B018F9A
html-safe-noncedd318914440505cea194d3c0a91e3fadf2c3e74c1353a8603a46b2fc36dc45ad
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjIyOjI0QTBBOjFENzAwQ0I6MjUyNzZBOTo2QjAxOEY5QSIsInZpc2l0b3JfaWQiOiI1MTc1NTc3MjA3MTM2OTQ4MTIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac3cff93127241bdc7df43e0f72ded9ecb30d5298c0e62b59aaccc28e1773eaf5f
hovercard-subject-tagissue:1576601369
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/52684/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4ea2183194c37d7f25b03d8a5bf7d84b5d7ac1d73a6337f7ba4f9d360a7d18f0/microsoft/TypeScript/issues/52684
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4ea2183194c37d7f25b03d8a5bf7d84b5d7ac1d73a6337f7ba4f9d360a7d18f0/microsoft/TypeScript/issues/52684
og:image:altBug Report 🕗 Version & Regression Information It's not a regression, the same behaviour can be observed on TS 4 and 5. (for TS 4, using ts-toolbelt's Narrow function gives equivalent results) 💻 Cod...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemocanew
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/52684#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F52684
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%2F52684
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/52684
Reloadhttps://github.com/microsoft/TypeScript/issues/52684
Reloadhttps://github.com/microsoft/TypeScript/issues/52684
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/52684
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/52684
#52769https://github.com/microsoft/TypeScript/pull/52769
False-positive errors regarding string array consthttps://github.com/microsoft/TypeScript/issues/52684#top
#52769https://github.com/microsoft/TypeScript/pull/52769
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 5.0.1https://github.com/microsoft/TypeScript/milestone/176
https://github.com/mocanew
Valentin Mocanu (mocanew)https://github.com/mocanew
on Feb 8, 2023https://github.com/microsoft/TypeScript/issues/52684#issue-1576601369
ts-toolbelthttps://github.com/millsp/ts-toolbelt
https://github.com/mocanew
Valentin Mocanu (mocanew)https://github.com/mocanew
on Feb 8, 2023https://github.com/microsoft/TypeScript/issues/52684#issuecomment-1423060252
const modifierhttps://github.com/microsoft/TypeScript/pull/51865
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Feb 10, 2023https://github.com/microsoft/TypeScript/issues/52684#issuecomment-1426043456
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Feb 10, 2023https://github.com/microsoft/TypeScript/issues/52684#event-8491613507
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Feb 10, 2023https://github.com/microsoft/TypeScript/issues/52684#event-8491613954
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
TypeScript 5.0.1https://github.com/microsoft/TypeScript/milestone/176
on Feb 10, 2023https://github.com/microsoft/TypeScript/issues/52684#event-8491614939
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Feb 10, 2023https://github.com/microsoft/TypeScript/issues/52684#issuecomment-1426062027
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 Feb 15, 2023https://github.com/microsoft/TypeScript/issues/52684#event-8520897492
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#52769https://github.com/microsoft/TypeScript/pull/52769
on Feb 18, 2023https://github.com/microsoft/TypeScript/issues/52684#event-8553554520
microsofthttps://github.com/microsoft
on Oct 22, 2025https://github.com/microsoft/TypeScript/issues/52684#event-20419503433
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/52684
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/52684
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 5.0.1https://github.com/microsoft/TypeScript/milestone/176
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.