{"action":"created","issue":{"url":"https://api.github.com/repos/typed-ember/ember-cli-typescript/issues/119","repository_url":"https://api.github.com/repos/typed-ember/ember-cli-typescript","labels_url":"https://api.github.com/repos/typed-ember/ember-cli-typescript/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/typed-ember/ember-cli-typescript/issues/119/comments","events_url":"https://api.github.com/repos/typed-ember/ember-cli-typescript/issues/119/events","html_url":"https://github.com/typed-ember/ember-cli-typescript/issues/119","id":297508484,"number":119,"title":"Service example needs clarification?","user":{"login":"tabeth","id":5572859,"avatar_url":"https://avatars0.githubusercontent.com/u/5572859?v=4","gravatar_id":"","url":"https://api.github.com/users/tabeth","html_url":"https://github.com/tabeth","followers_url":"https://api.github.com/users/tabeth/followers","following_url":"https://api.github.com/users/tabeth/following{/other_user}","gists_url":"https://api.github.com/users/tabeth/gists{/gist_id}","starred_url":"https://api.github.com/users/tabeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tabeth/subscriptions","organizations_url":"https://api.github.com/users/tabeth/orgs","repos_url":"https://api.github.com/users/tabeth/repos","events_url":"https://api.github.com/users/tabeth/events{/privacy}","received_events_url":"https://api.github.com/users/tabeth/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-15T16:24:36Z","updated_at":"2018-02-16T15:59:31Z","closed_at":"2018-02-16T15:59:31Z","author_association":"NONE","body":"Hello! \r\n\r\nWas wanting some clarity on the service injection example in `README.md`. \r\n\r\nIf you do the following:\r\n\r\n```typescript\r\n// my-app/services/session.ts\r\nimport Service from '@ember/service';\r\nimport RSVP from 'rsvp';\r\n\r\nexport default class Session extends Service {\r\n  login(email: string, password: string): RSVP.Promise<string> {\r\n    // login and return the confirmation message\r\n  }\r\n}\r\n\r\ndeclare module '@ember/service' {\r\n  interface Registry {\r\n    session: Session;\r\n  }\r\n}\r\n```\r\n\r\n```typescript\r\n// my-app/components/user-profile.ts\r\nimport Component from '@ember/component';\r\nimport { inject as service } from '@ember/service';\r\n\r\nexport default class UserProfile extends Component {\r\n  session = service('session');\r\n  init(this: UserProfile) {\r\n    this._super(...arguments);\r\n    this.get('session'); /* Undefined */\r\n  }\r\n}\r\n```\r\n\r\n---\r\n\r\nAs you can see, `session` is undefined in `init`, and most other places I've tried. I haven't tried it for `actions`, so maybe that's a unique case. In any case, the documentation currently makes it sound like following the example as shown above will make it work in a regular Ember fashion, but from my brief testing it looks like you actually need to do something like below to make it work.\r\n\r\n```typescript\r\n// my-app/components/user-profile.ts\r\nimport Component from '@ember/component';\r\nimport { inject as service } from '@ember/service';\r\n\r\nexport default class UserProfile extends Component.extend({\r\n  session: service('session');\r\n}) {\r\n  init(this: UserProfile) {\r\n    this._super(...arguments);\r\n    this.get('session'); /* Defined */\r\n  }\r\n}\r\n```\r\n\r\nIs this behavior by design, or is this a bug?"},"comment":{"url":"https://api.github.com/repos/typed-ember/ember-cli-typescript/issues/comments/366276237","html_url":"https://github.com/typed-ember/ember-cli-typescript/issues/119#issuecomment-366276237","issue_url":"https://api.github.com/repos/typed-ember/ember-cli-typescript/issues/119","id":366276237,"user":{"login":"tabeth","id":5572859,"avatar_url":"https://avatars0.githubusercontent.com/u/5572859?v=4","gravatar_id":"","url":"https://api.github.com/users/tabeth","html_url":"https://github.com/tabeth","followers_url":"https://api.github.com/users/tabeth/followers","following_url":"https://api.github.com/users/tabeth/following{/other_user}","gists_url":"https://api.github.com/users/tabeth/gists{/gist_id}","starred_url":"https://api.github.com/users/tabeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tabeth/subscriptions","organizations_url":"https://api.github.com/users/tabeth/orgs","repos_url":"https://api.github.com/users/tabeth/repos","events_url":"https://api.github.com/users/tabeth/events{/privacy}","received_events_url":"https://api.github.com/users/tabeth/received_events","type":"User","site_admin":false},"created_at":"2018-02-16T15:59:31Z","updated_at":"2018-02-16T15:59:31Z","author_association":"NONE","body":"It's my pleasure @chriskrycho.\r\n\r\nI created a brand new ember project and was not able to replicate the issue even though my project originally demonstrated the problem. Upon deleting `node_modules` and downloading the dependencies I was no longer to replicate the issue on my own project. For now I'll just chalk to this up to a stale build or some other shenanigans. If the problem crops up again I'll replicate it in a new repository and re-open the issue with a demonstration. "}}
{"actor":{"display_login":"tabeth"}}