{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4114","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4114/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4114/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4114/events","html_url":"https://github.com/Microsoft/TypeScript/issues/4114","id":98532894,"number":4114,"title":"Undefined 'design:paramtypes' metadata when param class is defined after","user":{"login":"pcan","id":10360978,"avatar_url":"https://avatars.githubusercontent.com/u/10360978?v=3","gravatar_id":"","url":"https://api.github.com/users/pcan","html_url":"https://github.com/pcan","followers_url":"https://api.github.com/users/pcan/followers","following_url":"https://api.github.com/users/pcan/following{/other_user}","gists_url":"https://api.github.com/users/pcan/gists{/gist_id}","starred_url":"https://api.github.com/users/pcan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcan/subscriptions","organizations_url":"https://api.github.com/users/pcan/orgs","repos_url":"https://api.github.com/users/pcan/repos","events_url":"https://api.github.com/users/pcan/events{/privacy}","received_events_url":"https://api.github.com/users/pcan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/In%20Discussion","name":"In Discussion","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-08-01T12:05:53Z","updated_at":"2015-08-03T20:13:43Z","closed_at":null,"body":"I have the following code:\r\n\r\n```\r\n@decorator\r\nclass A {\r\n    constructor(param : B) {\r\n\r\n    }\r\n}\r\n\r\nclass B {\r\n\r\n}\r\n\r\nfunction decorator(target: any) {\r\n    return target;\r\n}\r\n\r\nconsole.log(Reflect.getMetadata(\"design:paramtypes\", A));\r\n```\r\n\r\nThe expected output should be: `[function B()]`, but the actual output is `[undefined]`. The issue is related to the definition order in the resulting js file, in which there is the following code:\r\n\r\n```\r\nvar A = (function () {\r\n    function A(param) {\r\n    }\r\n    A = __decorate([\r\n        decorator, \r\n        __metadata('design:paramtypes', [B])\r\n    ], A);\r\n    return A;\r\n})();\r\nvar B = (function () {\r\n    function B() {\r\n    }\r\n    return B;\r\n})();\r\n```\r\n\r\nSince A is defined by a IIFE, in its execution scope B is not yet defined, so the generated metadata is incorrectly set to undefined. The only workaround I can use now is to declare B before A."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/127394044","html_url":"https://github.com/Microsoft/TypeScript/issues/4114#issuecomment-127394044","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4114","id":127394044,"user":{"login":"pcan","id":10360978,"avatar_url":"https://avatars.githubusercontent.com/u/10360978?v=3","gravatar_id":"","url":"https://api.github.com/users/pcan","html_url":"https://github.com/pcan","followers_url":"https://api.github.com/users/pcan/followers","following_url":"https://api.github.com/users/pcan/following{/other_user}","gists_url":"https://api.github.com/users/pcan/gists{/gist_id}","starred_url":"https://api.github.com/users/pcan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcan/subscriptions","organizations_url":"https://api.github.com/users/pcan/orgs","repos_url":"https://api.github.com/users/pcan/repos","events_url":"https://api.github.com/users/pcan/events{/privacy}","received_events_url":"https://api.github.com/users/pcan/received_events","type":"User","site_admin":false},"created_at":"2015-08-03T20:13:43Z","updated_at":"2015-08-03T20:13:43Z","body":"@wgebczyk My initial issue comment contained a solution similar to your proposal, but soon I edited and removed it, since there could be other unwanted side effects if some code immediately after the class declaration tries to query metadata, since it will be undefined until the \"end\" of the file.."}}