Skip to content

Commit 32d77d9

Browse files
mfeckiechriskrycho
authored andcommitted
Add some information about uninitialized class properties
1 parent af1d364 commit 32d77d9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ export default class UserProfile extends Component {
425425

426426
This also holds true for all other macros of the ember-decorators addon.
427427

428+
#### Typing uninitialized properties
429+
430+
For folks using babel@7 you may encounter problems when providing type definitions such as the following when working with Ember below `3.6`.
431+
432+
```ts
433+
import Component from '@ember/component';
434+
435+
export default class UserProfile extends Component {
436+
username?: string;
437+
}
438+
```
439+
440+
When invoked via a template `{{user-profile username='example123'}}`, you would expect that `username` would have the value of `example123`, however prior to the native class feature released in Ember `3.6`, this will result in `username` being undefined.
441+
428442
#### Ember Data lookups
429443

430444
We use the same basic approach for Ember Data type lookups with string keys as we do for service or controller injections. As a result, once you add the module and interface definitions for each model, serializer, and adapter in your app, you will automatically get type-checking and autocompletion and the correct return types for functions like `findRecord`, `queryRecord`, `adapterFor`, `serializerFor`, etc. No need to try to write out those (admittedly kind of hairy!) types; just write your Ember Data calls like normal and everything _should_ just work.

0 commit comments

Comments
 (0)