{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4521","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4521/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4521/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4521/events","html_url":"https://github.com/Microsoft/TypeScript/issues/4521","id":103711000,"number":4521,"title":"Classes passed to decorators dont work when there circular references used in those classes","user":{"login":"PLEEROCK","id":1753397,"avatar_url":"https://avatars.githubusercontent.com/u/1753397?v=3","gravatar_id":"","url":"https://api.github.com/users/PLEEROCK","html_url":"https://github.com/PLEEROCK","followers_url":"https://api.github.com/users/PLEEROCK/followers","following_url":"https://api.github.com/users/PLEEROCK/following{/other_user}","gists_url":"https://api.github.com/users/PLEEROCK/gists{/gist_id}","starred_url":"https://api.github.com/users/PLEEROCK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PLEEROCK/subscriptions","organizations_url":"https://api.github.com/users/PLEEROCK/orgs","repos_url":"https://api.github.com/users/PLEEROCK/repos","events_url":"https://api.github.com/users/PLEEROCK/events{/privacy}","received_events_url":"https://api.github.com/users/PLEEROCK/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-28T12:29:42Z","updated_at":"2015-08-28T22:44:16Z","closed_at":null,"body":"First I thought the problem in `reflect-metadata` component I used, but now I think the issue is with typescript decorators themself. I described that issue there: https://github.com/rbuckton/ReflectDecorators/issues/12\r\n\r\nYou can understand what is problem from my code out run output:\r\n\r\n```typescript\r\nimport {Person} from \"./Person\";\r\nimport {Relation} from \"./Relation\";\r\n\r\nexport class PersonInfo {\r\n    @Relation(Person)\r\n    info: string;\r\n}\r\n```\r\n\r\n```typescript\r\nimport {Relation} from \"./Relation\";\r\nimport {PersonInfo} from \"./PersonInfo\";\r\n\r\nexport class Person {\r\n    name: string;\r\n    @Relation(PersonInfo)\r\n    info: string;\r\n}\r\n```\r\n\r\n```typescript\r\nexport function Relation(cls) {\r\n    return function () {\r\n        console.log(cls);\r\n    }\r\n}\r\n```\r\n\r\n```typescript\r\nimport {Person} from \"./Person\";\r\nlet person = new Person();\r\n```\r\n\r\nresult:\r\n```\r\nundefined\r\n[Function: PersonInfo]\r\n```\r\nexpected result:\r\n```\r\n[Function: Person]\r\n[Function: PersonInfo]\r\n```\r\n\r\nFrom generated sources I found that Person_1.Person is undefined here:\r\n```js\r\n    __decorate([\r\n        Relation_1.Relation(Person_1.Person), \r\n        __metadata('design:type', String)\r\n    ], PersonInfo.prototype, \"info\");\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/135904889","html_url":"https://github.com/Microsoft/TypeScript/issues/4521#issuecomment-135904889","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4521","id":135904889,"user":{"login":"rbuckton","id":3902892,"avatar_url":"https://avatars.githubusercontent.com/u/3902892?v=3","gravatar_id":"","url":"https://api.github.com/users/rbuckton","html_url":"https://github.com/rbuckton","followers_url":"https://api.github.com/users/rbuckton/followers","following_url":"https://api.github.com/users/rbuckton/following{/other_user}","gists_url":"https://api.github.com/users/rbuckton/gists{/gist_id}","starred_url":"https://api.github.com/users/rbuckton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbuckton/subscriptions","organizations_url":"https://api.github.com/users/rbuckton/orgs","repos_url":"https://api.github.com/users/rbuckton/repos","events_url":"https://api.github.com/users/rbuckton/events{/privacy}","received_events_url":"https://api.github.com/users/rbuckton/received_events","type":"User","site_admin":false},"created_at":"2015-08-28T22:44:16Z","updated_at":"2015-08-28T22:44:16Z","body":"We've discussed this issue amongst the team in the past. We may need to change our `__metadata` helper to supply a function that when executed would return the metadata instead. This would help somewhat with issues with load order.\r\n\r\nIf we decide to go with that solution, the output from your example in rbuckton/ReflectDecorators#12 would instead look as follows:\r\n\r\n```js\r\n__decorate([\r\n    Relation_1.Relation(),\r\n    __metadata('design:type', function() { return Person_1.Person; })\r\n], PersonInfo.prototype, \"info\");\r\n```\r\n\r\nThen your call to Reflect.getMetadata would change to something like:\r\n\r\n```ts\r\n  let typefn = Reflect.getMetadata('design:type', object, propertyName);\r\n  let type = typefn();\r\n```\r\n\r\nYou still wouldn't be able to get the 'design:type' if the constructor from the external file has still not yet been exported, but there is no way around that given the execution semantics of JavaScript.\r\n\r\n"}}