{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6122","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6122/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6122/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6122/events","html_url":"https://github.com/Microsoft/TypeScript/issues/6122","id":122637601,"number":6122,"title":"Getting Promise implementation for async methods from a property of the current class","user":{"login":"thorn0","id":94334,"avatar_url":"https://avatars.githubusercontent.com/u/94334?v=3","gravatar_id":"","url":"https://api.github.com/users/thorn0","html_url":"https://github.com/thorn0","followers_url":"https://api.github.com/users/thorn0/followers","following_url":"https://api.github.com/users/thorn0/following{/other_user}","gists_url":"https://api.github.com/users/thorn0/gists{/gist_id}","starred_url":"https://api.github.com/users/thorn0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thorn0/subscriptions","organizations_url":"https://api.github.com/users/thorn0/orgs","repos_url":"https://api.github.com/users/thorn0/repos","events_url":"https://api.github.com/users/thorn0/events{/privacy}","received_events_url":"https://api.github.com/users/thorn0/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20Proposal","name":"Needs Proposal","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":1,"created_at":"2015-12-17T00:50:02Z","updated_at":"2015-12-18T04:30:27Z","closed_at":null,"body":"As per @rbuckton in #3364:\r\n\r\n> For an async function, the return type annotation must be both a type and a value in the same scope.\r\n\r\nIt's nice as it allows using any compatible Promise implementation. However, it requires that this implementation should be assigned to a variable in the scope. Unfortunately, this doesn't always work well with Angular 1.x, whose approach discourages globals in favour of dependency injection for the sake of testability. Consider this code of an Angular controller:\r\n\r\n```ts\r\ntype $q<T> = Promise<T>;\r\nclass MainController {\r\n    public name: string;\r\n    constructor(private $q: PromiseConstructor, private myService: MyService) {}\r\n    async fn1(): $q<void> {\r\n        this.name = await this.myService.fn1();\r\n    }\r\n}\r\nmodule.angular('myApp').controller('MainController', MainController);\r\n```\r\n\r\nThe promise implementation `$q` is injected to the constructor by Angular here. Of course, it doesn't work as TypeScript looks for `$q`, not for `this.$q`. So as for now, the only solution for this situation is saving `$q` to a global variable. Please consider adding the property lookup for async methods."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/165671267","html_url":"https://github.com/Microsoft/TypeScript/issues/6122#issuecomment-165671267","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6122","id":165671267,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T04:30:27Z","updated_at":"2015-12-18T04:30:27Z","body":"You mean being able to write the following?\r\n\r\n```ts\r\n    async fn1(): this.$q<void> {\r\n        this.name = await this.myService.fn1();\r\n    }\r\n```"}}