{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3056","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3056/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3056/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3056/events","html_url":"https://github.com/Microsoft/TypeScript/issues/3056","id":73715645,"number":3056,"title":"Recognize type definitions in ctor-like functions","user":{"login":"jrieken","id":1794099,"avatar_url":"https://avatars.githubusercontent.com/u/1794099?v=3","gravatar_id":"","url":"https://api.github.com/users/jrieken","html_url":"https://github.com/jrieken","followers_url":"https://api.github.com/users/jrieken/followers","following_url":"https://api.github.com/users/jrieken/following{/other_user}","gists_url":"https://api.github.com/users/jrieken/gists{/gist_id}","starred_url":"https://api.github.com/users/jrieken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrieken/subscriptions","organizations_url":"https://api.github.com/users/jrieken/orgs","repos_url":"https://api.github.com/users/jrieken/repos","events_url":"https://api.github.com/users/jrieken/events{/privacy}","received_events_url":"https://api.github.com/users/jrieken/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-06T19:36:12Z","updated_at":"2015-05-07T00:32:46Z","closed_at":null,"body":"You will encounter the pattern below very often in the wild. Despite TypeScript having classes as a valid replacement, this should be support IMO, especially when migration a code base or when looking at plain JS code.\r\n\r\n```\r\nfunction X() {\r\n       this.foo = \"123\";\r\n};\r\n\r\nvar y = new X();\r\ny.foo; //should be known\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/99658932","html_url":"https://github.com/Microsoft/TypeScript/issues/3056#issuecomment-99658932","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3056","id":99658932,"user":{"login":"danquirk","id":7121557,"avatar_url":"https://avatars.githubusercontent.com/u/7121557?v=3","gravatar_id":"","url":"https://api.github.com/users/danquirk","html_url":"https://github.com/danquirk","followers_url":"https://api.github.com/users/danquirk/followers","following_url":"https://api.github.com/users/danquirk/following{/other_user}","gists_url":"https://api.github.com/users/danquirk/gists{/gist_id}","starred_url":"https://api.github.com/users/danquirk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danquirk/subscriptions","organizations_url":"https://api.github.com/users/danquirk/orgs","repos_url":"https://api.github.com/users/danquirk/repos","events_url":"https://api.github.com/users/danquirk/events{/privacy}","received_events_url":"https://api.github.com/users/danquirk/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T00:32:46Z","updated_at":"2015-05-07T00:32:46Z","body":"There're definitely a couple other bugs that cover this suggestion already. @RyanCavanaugh and I have talked about this recently as far as exactly what supporting it would look like. Even in a class context we will potentially want to recognize this pattern as JS users will be migrating code like above as well as classes with actual constructors but no type information. A set of assignments to this.<expression> (they need not be contiguous) could be understood to define an inferred shape for the type as long as there are no instance fields defined (since at that point you'd have already opted into TypeScript syntax and should finish the job by describing the fields that will be assigned via this.<expression> in the constructor)."}}