Skip to content

Commit 0088628

Browse files
Merge branch 'master' into allenylzhou/ignore-node-modules
2 parents d620b8d + 3a59392 commit 0088628

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
## [1.3.3] - 2018-07-19
10+
11+
### Fixed
12+
13+
* Watcher has been "de-simplified" to make it more consistent with how tsc's own watcher works and prevent rebuild issues.
14+
* `ember-cli-typescript` will now run after `ember-decorators`, ensuring that the `ember-cli-typescript` blueprints override `ember-decorators`'.
15+
16+
### Changed
17+
18+
* Improved documentation regarding service injection.
19+
20+
### Added
21+
22+
* Getting Help section to readme.
23+
* Github issue templates.
24+
925
## [1.3.2] - 2018-06-05
1026

1127
### Fixed
@@ -238,7 +254,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
238254
* Basic, semi-working functionality.
239255

240256
[ember-cli-typify]: https://github.com/winding-lines/ember-cli-typify
241-
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.3.2...HEAD
257+
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.3.3...HEAD
258+
[1.3.3]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.3.2...v1.3.3
242259
[1.3.2]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.3.1...v1.3.2
243260
[1.3.1]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.3.0...v1.3.1
244261
[1.3.0]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.2.1...v1.3.0

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ declare module '@ember/service' {
306306
}
307307
```
308308

309-
(If you're converting an existing service, remember to add the module declaration at the end. This is what we'll use to tell TypeScript what the type of the service is in the injection.)
309+
You'll need to add that module and interface declaration to all your existing service and controller declarations for this to work (again, see the [blog post][pt4] for further details), but once you do that, you'll have this much nicer experience throughout! It's not quite vanilla Ember.js, but it's close—and this way, you still get all those type-checking and auto-completion benefits, but with a lot less noise! Moreover, you actually get a significant benefit over "vanilla" Ember: we type-check that you typed the key correctly in the `service` invocation.
310310

311311
Then we can use the service as usual:
312312

@@ -341,7 +341,7 @@ import { service } from '@ember-decorators/service';
341341
import MySession from 'my-app/services/my-session';
342342

343343
export default class UserProfile extends Component {
344-
@service mySession: MySession;
344+
@service mySession!: MySession;
345345

346346
login(this: UserProfile, email: string, password: string) {
347347
this.session.login(email, password);
@@ -351,7 +351,28 @@ export default class UserProfile extends Component {
351351

352352
Note that we need the `MySession` type annotation this way, but we *don't* need the string lookup (unless we're giving the service a different name than the usual on the class, as in Ember injections in general). Without the type annotation, the type of `session` would just be `any`. This is because decorators (as of TS 2.8 – 3.0) are not allowed to modify the types of whatever they decorate. As a result, we wouldn't get any type-checking on that `session.login` call, and we wouldn't get any auto-completion either. Which would be really sad and take away a lot of the reason we're using TypeScript in the first place!
353353

354-
You'll need to add that module and interface declaration to all your existing service and controller declarations for this to work (again, see the [blog post][pt4] for further details), but once you do that, you'll have this much nicer experience throughout! It's not quite vanilla Ember.js, but it's close—and this way, you still get all those type-checking and auto-completion benefits, but with a lot less noise! Moreover, you actually get a significant benefit over "vanilla" Ember: we type-check that you typed the key correctly in the `service` invocation.
354+
Also use the [`!` non-null assertion operator](https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#non-null-assertion-operator) to prevent [`TS2564`](https://github.com/kaorun343/vue-property-decorator/issues/81), that is caused by enabling `strictPropertyInitialization` in `tsconfig.json`.
355+
356+
If you're on an Ember version below 3.1, you'll want to wrap your service type in [`ComputedProperty`](https://www.emberjs.com/api/ember/release/classes/ComputedProperty), because [native ES5 getters](https://github.com/emberjs/rfcs/blob/master/text/0281-es5-getters.md) are not available there, which means that instead of accessing the service via `this.mySession`, you would have to access it as `this.get('mySession')` or `get(this, 'mySession')`. This means the above code would rather look like:
357+
358+
```ts
359+
// my-app/components/user-profile.ts
360+
import Component from '@ember/component';
361+
import { get } from '@ember/object';
362+
import ComputedProperty from '@ember/object/computed';
363+
import { service } from '@ember-decorators/service';
364+
import MySession from 'my-app/services/my-session';
365+
366+
export default class UserProfile extends Component {
367+
@service mySession!: ComputedProperty<MySession>;
368+
369+
login(this: UserProfile, email: string, password: string) {
370+
get(this, 'session').login(email, password);
371+
}
372+
}
373+
```
374+
375+
This also holds true for all other macros of the ember-decorators addon.
355376

356377
#### Ember Data lookups
357378

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-typescript",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Allow ember apps to use typescript files.",
55
"keywords": [
66
"ember-addon",
@@ -115,7 +115,8 @@
115115
],
116116
"after": [
117117
"ember-source",
118-
"ember-data"
118+
"ember-data",
119+
"ember-decorators"
119120
],
120121
"paths": [
121122
"tests/dummy/lib/in-repo-a",

0 commit comments

Comments
 (0)