René's URL Explorer Experiment


Title: Recursive inference through self-referential object literals · Issue #64192 · microsoft/TypeScript · GitHub

Open Graph Title: Recursive inference through self-referential object literals · Issue #64192 · microsoft/TypeScript

X Title: Recursive inference through self-referential object literals · Issue #64192 · microsoft/TypeScript

Description: A library that derives static types from a runtime description of data has to let a schema reference itself, or it can't describe recursive data. The only place to put that self-reference is a getter, because category has no type until i...

Open Graph Description: A library that derives static types from a runtime description of data has to let a schema reference itself, or it can't describe recursive data. The only place to put that self-reference is a gett...

X Description: A library that derives static types from a runtime description of data has to let a schema reference itself, or it can't describe recursive data. The only place to put that self-reference is a ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recursive inference through self-referential object literals","articleBody":"A library that derives static types from a runtime description of data has to let a schema reference itself, or it can't describe recursive data. The only place to put that self-reference is a getter, because `category` has no type until its own declaration finishes.\n\n```ts\nconst category = object({\n  name: string(),\n  get subcategories() {\n    return array(category);\n  },\n});\n```\n\nThat doesn't infer. Both declarations collapse to `any`:\n\n```\nerror TS7022: 'category' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.\nerror TS7023: 'subcategories' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.\n```\n\nThe annotation the error asks for is the type that inference was supposed to produce, so there is nothing the author can write in its place.\n\n## The workaround\n\n[colinhacks/recursive-inference](https://github.com/colinhacks/recursive-inference) has two copies of a small schema library. One is written the normal way and one is written the way Zod actually does it. Both declare the same five recursive schemas.\n\nThe normal version, `idiomatic.ts`, takes output and input as ordinary type parameters, constrains every parameter against the real base interface, and reads the output type back with an indexed access. It produces 11 of the errors above on TypeScript 7, and the same 11 on 5.9.3 and 5.5.4.\n\nThe other version, `shipped.ts`, has the workarounds Zod ships. It compiles. The constraint is replaced with a structural type that doesn't mention the parameters, and the output type is read through a conditional type so the lookup is deferred.\n\n```ts\n// idiomatic: the constraint says what a schema is, and the read is direct\nexport type output\u003cT extends $ZodType> = T[\"_zod\"][\"output\"];\nexport interface $ZodArray\u003cT extends $ZodType = $ZodType> extends $ZodType\u003coutput\u003cT>[], input\u003cT>[]> {}\n\n// what ships: the constraint discards the parameters, and the read defers\nexport type SomeType = { _zod: _$ZodTypeInternals };\nexport type output\u003cT> = T extends { _zod: { output: any } } ? T[\"_zod\"][\"output\"] : unknown;\nexport interface $ZodArray\u003cT extends SomeType = $ZodType> extends $ZodType {\n  _zod: $ZodArrayInternals\u003cT>;\n}\n```\n\nZod does this at 296 sites so that recursive schemas infer for users. The `SomeType` constraint accepts anything with the right shape of internals, so at those sites Zod can't constrain a parameter to be a schema.\n\n## Other libraries\n\nRecursive data is common: category trees, comment threads, filesystem nodes, self-referencing foreign keys, state machines whose transitions name other states, agents whose handoffs name other agents. Any library that derives a static type from a runtime description of that data hits the same problem.\n\nZod absorbs the cost inside the library, at those 296 sites, so users don't see it.\n\nDrizzle puts it on the user. A self-referencing foreign key needs a hand-written return type:\n\n```ts\nreportsTo: integer('reports_to').references((): AnyPgColumn => employees.id),\n```\n\nWithout the annotation the arrow's return type is inferred from `employees`, which is still being declared, and that is the same failure. The annotation appears throughout Drizzle's own tests and docs. The `AnyPgColumn` type is the same kind of widened stand-in as Zod's `SomeType`. It means some column of some table, because the real column type can't be named yet.\n\nNeither cost shows up as a bug report. From the outside both features work; Zod infers recursive schemas and Drizzle links self-referencing tables.\n\n## Scope\n\nI don't know how big the general problem is. [#64172](https://github.com/microsoft/TypeScript/pull/64172) fixes the case above, and with it all 296 of Zod's substitutions can be deleted. It has tests and measurements, but it is a fix for one shape, not a general design. A design that covers more of this would be better than the specific fix.\n","author":{"url":"https://github.com/colinhacks","@type":"Person","name":"colinhacks"},"datePublished":"2026-09-07T19:13:24Z","url":"https://github.com/microsoft/TypeScript/issues/64192"}

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:d0c5d5f8-b787-127b-58a1-3f739981b7a3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBFC8:DA744:AC7615:E8C148:6B00F4FC
html-safe-noncebfb63099986fa55b589db9c5aaa81b6aa3ed96d036ef0d1e4541ef6acfaa6f5b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkM4OkRBNzQ0OkFDNzYxNTpFOEMxNDg6NkIwMEY0RkMiLCJ2aXNpdG9yX2lkIjoiNjYzNTIzNzMzMDMzNDU3NzkxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1c58526f1d13ab847368e6183244b326781631f02bc280bdeb94de2be4586420
hovercard-subject-tagissue:5378261925
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/64192/issue_layout
twitter:imagehttps://opengraph.githubassets.com/15b35306123211d10029c9e407670c766bdd3681557e545e19d1b5ae9472a3c8/microsoft/TypeScript/issues/64192
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/15b35306123211d10029c9e407670c766bdd3681557e545e19d1b5ae9472a3c8/microsoft/TypeScript/issues/64192
og:image:altA library that derives static types from a runtime description of data has to let a schema reference itself, or it can't describe recursive data. The only place to put that self-reference is a gett...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecolinhacks
hostnamegithub.com
expected-hostnamegithub.com
None4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc
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
release9983dd5da06943f833c971dd5b6bc988e2858be5
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/64192#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F64192
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%2F64192
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/64192
Reloadhttps://github.com/microsoft/TypeScript/issues/64192
Reloadhttps://github.com/microsoft/TypeScript/issues/64192
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests308 (308)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/64192
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/64192
#64311https://github.com/microsoft/TypeScript/pull/64311
Recursive inference through self-referential object literalshttps://github.com/microsoft/TypeScript/issues/64192#top
#64311https://github.com/microsoft/TypeScript/pull/64311
https://github.com/ahejlsberg
Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some caseshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Possible%20Improvement%22
TypeScript 7.1.0 Betahttps://github.com/microsoft/TypeScript/milestone/224
https://github.com/colinhacks
Colin McDonnell (colinhacks)https://github.com/colinhacks
on Sep 7, 2026https://github.com/microsoft/TypeScript/issues/64192#issue-5378261925
colinhacks/recursive-inferencehttps://github.com/colinhacks/recursive-inference
#64172https://github.com/microsoft/TypeScript/pull/64172
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 Sep 8, 2026https://github.com/microsoft/TypeScript/issues/64192#event-30781921173
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Sep 8, 2026https://github.com/microsoft/TypeScript/issues/64192#event-30781923918
https://github.com/colinhacks
Colin McDonnell (colinhacks)https://github.com/colinhacks
on Sep 9, 2026https://github.com/microsoft/TypeScript/issues/64192#issuecomment-5594283251
#64172https://github.com/microsoft/TypeScript/pull/64172
https://github.com/devanshj
Devansh Jethmalani (devanshj)https://github.com/devanshj
on Sep 9, 2026https://github.com/microsoft/TypeScript/issues/64192#issuecomment-5606700713
#64091https://github.com/microsoft/TypeScript/issues/64091
#64092https://github.com/microsoft/TypeScript/pull/64092
https://private-user-images.githubusercontent.com/30295578/648893267-14ab268d-0600-402a-b5a1-c84c4a8a2dad.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyMjUxMjksIm5iZiI6MTc5NTIyNDgyOSwicGF0aCI6Ii8zMDI5NTU3OC82NDg4OTMyNjctMTRhYjI2OGQtMDYwMC00MDJhLWI1YTEtYzg0YzRhOGEyZGFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTIxVDAxMzM0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlhNDZmYWVmNzE5MWQ5YTUwMWIxOTFiZGY5MDY3NTkzZGMxMDJkZTkzZDQ2MTU4MzM5ZTgxMmRiYzJjOGYzODUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.aAOMQ0JEOdDnpyaN8CtYHoUs-8oZGDO2XD9T07eKx9M
https://github.com/devanshj
Devansh Jethmalani (devanshj)https://github.com/devanshj
on Sep 10, 2026https://github.com/microsoft/TypeScript/issues/64192#issuecomment-5616093710
https://private-user-images.githubusercontent.com/30295578/649347743-92baec51-64d5-40dd-b199-51c517cb54a4.png?jwt=eyJ0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TI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTIxVDAxMzM0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUyYmUwMjM1NWIyMWMyNTBmYjlmZDM2NThjMzI1NTdkOTkzNDU0ZTM4ZGVlN2FhMDIzNjFkNDdmNDE0MzBkZDUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.4RQtg5MyH9eix2yshOpUncT4lvAXEFvWdnOxvRUWx84
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some caseshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Possible%20Improvement%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 Sep 17, 2026https://github.com/microsoft/TypeScript/issues/64192#event-31335248620
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
TypeScript 7.1.0 Betahttps://github.com/microsoft/TypeScript/milestone/224
on Sep 17, 2026https://github.com/microsoft/TypeScript/issues/64192#event-31335279827
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#64311https://github.com/microsoft/TypeScript/pull/64311
on Sep 18, 2026https://github.com/microsoft/TypeScript/issues/64192#event-31359962784
Jarred Sumner (Jarred-Sumner)https://github.com/Jarred-Sumner
on Oct 21, 2026https://github.com/microsoft/TypeScript/issues/64192#event-33806200493
`bun check`: no constraint checks in a recursive resolution of a callhttps://github.com/oven-sh/bun/commit/2fb5392dd785d207162d3f314e3ea5dc9be0673a
2fb5392https://github.com/oven-sh/bun/commit/2fb5392dd785d207162d3f314e3ea5dc9be0673a
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/64192
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/64192
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some caseshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Possible%20Improvement%22
TypeScript 7.1.0 BetaNo due datehttps://github.com/microsoft/TypeScript/milestone/224
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.