René's URL Explorer Experiment


Title: loading, declaration and execution phases of modules and cyclic references problem ? · Issue #7282 · microsoft/TypeScript · GitHub

Open Graph Title: loading, declaration and execution phases of modules and cyclic references problem ? · Issue #7282 · microsoft/TypeScript

X Title: loading, declaration and execution phases of modules and cyclic references problem ? · Issue #7282 · microsoft/TypeScript

Description: This question is related to TypeScript, ES6, SystemJs and ReflectJs specs, but I would like to know your thoughts about it. So for a function declarations the sequence of code is not important, but for classes it is: Example with single ...

Open Graph Description: This question is related to TypeScript, ES6, SystemJs and ReflectJs specs, but I would like to know your thoughts about it. So for a function declarations the sequence of code is not important, but...

X Description: This question is related to TypeScript, ES6, SystemJs and ReflectJs specs, but I would like to know your thoughts about it. So for a function declarations the sequence of code is not important, but...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"loading, declaration and execution phases of modules and cyclic references problem ?","articleBody":"This question is related to TypeScript, ES6, SystemJs and ReflectJs specs, but I would like to know your thoughts about it. \n\nSo for a function declarations the sequence of code is not important, but for classes it is: \n### Example with single module\n\n``` ts\nconsole.info(fnc()); // this is fine\nconsole.info(new Cls()); //TypeError: Cls is not a constructor\nfunction fnc(){\n  return \"value\"\n}\nclass Cls {\n  constructor(){\n    //...\n  }\n}\n```\n\nA more complex example when classes located in different modules and have cross references in declaration phase like:\n### Example with multiple modules and static references\n\n``` ts\n// one.ts\nimport {Two} from \"./two\"\nclass One {\n  static two = new One();\n}\n// two.ts\nimport {One} from \"./one\"\nclass One {\n  static two = new One(); //TypeError: One is not a function \n}\n//main.ts\nimport {One} from \"./one\"\nimport {Two} from \"./two\"\nconsole.info(One.two) \nconsole.info(Two.one)\n\n```\n\nso this is throwing error when trying to create `One` instace, the expectation is to have `One` declared at the time of exection .\n\nThis can be hacked by using some cached getters, which can be somehow used to solve the main problem in runtime(loader) :\n\n``` ts\n// cached.ts\nexport function Cached(target,key,desc){\n    var initializer = desc.get;\n    desc.get = function(){\n        return Object.defineProperty(this,key,{\n            value:initializer()\n        })[key];\n    };\n    return desc;\n}\n// one.ts\nimport {Cached} from \"./cached\";\nimport {Two} from \"./two\";\nexport class One {\n    @Cached\n    static get two():Two{\n        return new Two()\n    }\n}\n// two.ts\nimport {Cached} from \"./cached\";\nimport {One} from \"./one\";\nexport class Two {\n    @Cached\n    static get one():One{\n        return new One();\n    }\n}\n//main.ts\nimport {One} from \"./one\"\nimport {Two} from \"./two\"\nconsole.info(One.two) \nconsole.info(Two.one)\n\n```\n\nI have prepared some demo to show hack on this problem, you can see bellow \n\n**Expected behavior:**\n\n[Create and instance of `Cls` and out put it without errors. ](http://casser.github.io/typescript-cyclic-references-problem/cyclic-hack.html)\n\n**Actual behavior:** \n\n[Throws a `TypeError` because of undeclared class](http://casser.github.io/typescript-cyclic-references-problem/cyclic-problem.html)\n### Example of cyclic references problem in decoration phase\n\nThe other example is [annotators cyclic references problem](http://casser.github.io/typescript-cyclic-references-problem/decors-problem.html).\n\n``` ts\nfunction Model(target){}\nfunction Collection(target){}\nfunction Field(target:any,key:any,desc?:any):any{\n    var type:any = Reflect.getMetadata(\"design:type\",target,key);\n    document.write(`\u003cpre>${target.constructor.name}.${key} : ${type?type.name:\"\u003cspan style='color: red'>UNDEFINED ?\u003c/span>\"}\u003c/pre>`);\n}\n\n@Model\nexport class User {\n    @Field id:String;\n    @Field name:String;\n    @Field projects:Projects; // Project Is not defined yet\n}\n\n@Collection\nexport class Users extends Array\u003cUser> {}\n\n@Model\nexport class Project {\n    @Field id:String;\n    @Field name:String;\n    @Field author:User;\n    @Field contributors:Users; // Users will not be defined \n                               // if we will change definition order\n}\n\n@Collection\nexport class Projects extends Array\u003cProject>{}\n```\n\nI think this is **IMPORTANT** because `Dependecy Injection (java guice)`, `ORM's` or `Serialization` frameworks will use this feature deeply, and user code can contain _cross referenced types_.\n\nSo the main reason for this problem is that declaration, decoration and execution phases of classes mixed in output. \n\n``` js\n// decoration inside execution block and part of class declaration \n__decorate([\n    Field, \n    __metadata('design:type', Projects)\n], User.prototype, \"projects\", void 0);\n```\n\nPotencial hack for this can be generate closure instead of direct type referance in metadata like:\n\n``` js\n__decorate([\n    Field, \n    __metadata('design:type', function(){return Projects})\n], User.prototype, \"projects\", void 0);\n```\n\nwhich can be adjusted after module execution, but I think this is just a hack, and the right way will be finnaly define \nspecification about _Loading > Declaration > Annotation > Decoration and Execution_ phases of runtime which will support cyclic references. \n\nAny thoughts ?  \n\nPS: AND AGAIN THANKS FOR `TYPESCRIPT` :)\n","author":{"url":"https://github.com/casser","@type":"Person","name":"casser"},"datePublished":"2016-02-28T15:35:08Z","url":"https://github.com/microsoft/TypeScript/issues/7282"}

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:efdb031b-5270-42ca-63bd-5b753faeb1b1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE42C:14F601:27E4BBF:32A0AE3:6B0180FF
html-safe-nonce069ea03b4f75434c9ec0c10220ece63a82bb5df8db744b34d32ef245d9ac7dfd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDJDOjE0RjYwMToyN0U0QkJGOjMyQTBBRTM6NkIwMTgwRkYiLCJ2aXNpdG9yX2lkIjoiNTg5NTUyOTY1MTQwODgzMDcxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac4c4af29a1f4eb4c0d21e856430c074853c62be220e08511e4ac53ea0405f6f89
hovercard-subject-tagissue:137064189
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/7282/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8329dd03e49c389d89ba7eb40c69ef23f9cf1c5366ed7fff9babaa0427670bdc/microsoft/TypeScript/issues/7282
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8329dd03e49c389d89ba7eb40c69ef23f9cf1c5366ed7fff9babaa0427670bdc/microsoft/TypeScript/issues/7282
og:image:altThis question is related to TypeScript, ES6, SystemJs and ReflectJs specs, but I would like to know your thoughts about it. So for a function declarations the sequence of code is not important, but...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecasser
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/7282#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F7282
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%2F7282
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/7282
Reloadhttps://github.com/microsoft/TypeScript/issues/7282
Reloadhttps://github.com/microsoft/TypeScript/issues/7282
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/7282
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/7282
loading, declaration and execution phases of modules and cyclic references problem ?https://github.com/microsoft/TypeScript/issues/7282#top
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/casser
Sergey Mamyan (casser)https://github.com/casser
on Feb 28, 2016https://github.com/microsoft/TypeScript/issues/7282#issue-137064189
Create and instance of Cls and out put it without errors. http://casser.github.io/typescript-cyclic-references-problem/cyclic-hack.html
Throws a TypeError because of undeclared classhttp://casser.github.io/typescript-cyclic-references-problem/cyclic-problem.html
annotators cyclic references problemhttp://casser.github.io/typescript-cyclic-references-problem/decors-problem.html
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Feb 28, 2016https://github.com/microsoft/TypeScript/issues/7282#issuecomment-189942786
Sergey Mamyan (@casser)https://github.com/casser
https://github.com/casser
Sergey Mamyan (casser)https://github.com/casser
on Feb 29, 2016https://github.com/microsoft/TypeScript/issues/7282#issuecomment-189973483
Demohttp://casser.github.io/typescript-cyclic-references-problem/cyclic-problem.html
Demohttp://casser.github.io/typescript-cyclic-references-problem/decors-problem.html
repohttps://github.com/casser/typescript-cyclic-references-problem
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Feb 29, 2016https://github.com/microsoft/TypeScript/issues/7282#issuecomment-190018304
Ron Buckton (@rbuckton)https://github.com/rbuckton
#4114https://github.com/microsoft/TypeScript/issues/4114
#21https://github.com/microsoft/TypeScript/issues/21
#4341https://github.com/microsoft/TypeScript/issues/4341
#5207https://github.com/microsoft/TypeScript/issues/5207
#4343https://github.com/microsoft/TypeScript/pull/4343
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Feb 29, 2016https://github.com/microsoft/TypeScript/issues/7282#issuecomment-190322000
#21https://github.com/microsoft/TypeScript/issues/21
#4341https://github.com/microsoft/TypeScript/issues/4341
#5207https://github.com/microsoft/TypeScript/issues/5207
#4343https://github.com/microsoft/TypeScript/pull/4343
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
#5207https://github.com/microsoft/TypeScript/issues/5207
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
on Feb 29, 2016https://github.com/microsoft/TypeScript/issues/7282#event-571571580
https://github.com/rbuckton
Ron Buckton (rbuckton)https://github.com/rbuckton
on Feb 29, 2016https://github.com/microsoft/TypeScript/issues/7282#issuecomment-190403588
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Mar 29, 2016https://github.com/microsoft/TypeScript/issues/7282#event-606134871
https://github.com/pie6k
Adam Pietrasiak (pie6k)https://github.com/pie6k
on Oct 30, 2017https://github.com/microsoft/TypeScript/issues/7282#issuecomment-340507483
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/7282#event-1689640920
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/7282
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/7282
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
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.