Skip to content

Commit e55338e

Browse files
committed
docs: update from GitBook -- 37 pages modified
1 parent 3a434de commit e55338e

37 files changed

+460
-534
lines changed

docs/SUMMARY.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Table of contents
2+
3+
* [Initial page](../index.md)
4+
* [Getting Started](getting-started/README.md)
5+
* [Installation](getting-started/installation.md)
6+
* [Configuration](getting-started/configuration.md)
7+
* [Working With Ember Classic](legacy/README.md)
8+
* [EmberComponent](legacy/ember-component.md)
9+
* [Mixins](legacy/mixins.md)
10+
* [Computed Properties](legacy/computed-properties.md)
11+
* [EmberObject](legacy/ember-object.md)
12+
* [Legacy Ember Guide](legacy/overview.md)
13+
* [Working With Ember Data](ember-data/README.md)
14+
* [Overview: Ember Data](ember-data/overview.md)
15+
* [Models](ember-data/models.md)
16+
* [cookbook](cookbook/README.md)
17+
* [Overview](cookbook/overview.md)
18+
* [Working with route models](cookbook/working-with-route-models.md)
19+
* [type-defs](type-defs/README.md)
20+
* [Understanding the Package Names](type-defs/package-names.md)
21+
* [Overview](index.md)
22+
* [ts](ts/README.md)
23+
* [Building Addons in TypeScript](ts/with-addons.md)
24+
* [TypeScript and Ember](ts/overview.md)
25+
* [Decorators](ts/decorators.md)
26+
* [Using TypeScript with Ember effectively](ts/using-ts-effectively.md)
27+
* [Current limitations](ts/current-limitations.md)
28+
* [Upgrading from 1.x](upgrade-notes.md)
29+
* [Working With Ember](ember/README.md)
30+
* [Controllers](ember/controllers.md)
31+
* [Services](ember/services.md)
32+
* [Overview: Ember](ember/overview.md)
33+
* [Testing](ember/testing.md)
34+
* [Components](ember/components.md)
35+
* [Helpers](ember/helpers.md)
36+
* [Routes](ember/routes.md)
37+
* [troubleshooting](troubleshooting/README.md)
38+
* [Conflicting Type Dependencies](troubleshooting/conflicting-types.md)
39+

docs/cookbook/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# cookbook
2+

docs/cookbook/overview.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
This “cookbook” section contains recipes for various scenarios you may encounter while working on your app or addon.
44

55
{% hint style="info" %}
6-
7-
Have an idea for an item that should fit here? [Open an issue for it!][gh-issue] We'd love to help you help us make this experience more awesome for everyone.
8-
9-
[gh-issue]: https://github.com/typed-ember/ember-cli-typescript/issues/new/choose
10-
6+
Have an idea for an item that should fit here? [Open an issue for it!](https://github.com/typed-ember/ember-cli-typescript/issues/new/choose) We'd love to help you help us make this experience more awesome for everyone.
117
{% endhint %}
128

13-
- <LinkTo @route='docs.cookbook.working-with-route-models'>Working with route models</LinkTo>
9+
* Working with route models
10+

docs/cookbook/working-with-route-models.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ We often use routes’ models throughout our application, since they’re a core
44

55
We can start by defining some type utilities to let us get the resolved value returned by a route’s model hook:
66

7-
```ts
7+
```typescript
88
import Route from '@ember/routing/route';
99

1010
/**
@@ -21,21 +21,21 @@ export type ModelFrom<R extends Route> = Resolved<ReturnType<R['model']>>;
2121

2222
How that works:
2323

24-
- `Resolved<P>` says "if this is a promise, the type here is whatever the promise resolves to; otherwise, it's just the value"
25-
- `ReturnType<T>` gets the return value of a given function
26-
- `R['model']` (where `R` has to be `Route` itself or a subclass) uses TS's mapped types to say "the property named `model` on `R`
24+
* `Resolved<P>` says "if this is a promise, the type here is whatever the promise resolves to; otherwise, it's just the value"
25+
* `ReturnType<T>` gets the return value of a given function
26+
* `R['model']` \(where `R` has to be `Route` itself or a subclass\) uses TS's mapped types to say "the property named `model` on `R`
2727

28-
Putting those all together, `ModelFrom<Route>` ends up giving you the resolved value returned from the `model` hook for a given route:
28+
Putting those all together, `ModelFrom<Route>` ends up giving you the resolved value returned from the `model` hook for a given route:
2929

30-
```ts
30+
```typescript
3131
type MyRouteModel = ModelFrom<MyRoute>;
3232
```
3333

3434
## `model` on the controller
3535

3636
We can use this functionality to guarantee that the `model` on a `Controller` is always exactly the type returned by `Route::model` by writing something like this:
3737

38-
```ts
38+
```typescript
3939
import Controller from '@ember/controller';
4040
import MyRoute from '../routes/my-route';
4141
import { ModelFrom } from '../lib/type-utils';
@@ -45,6 +45,7 @@ export default class ControllerWithModel extends Controller {
4545
}
4646
```
4747

48-
Now, our controller’s `model` property will *always* stay in sync with the corresponding route’s model hook.
48+
Now, our controller’s `model` property will _always_ stay in sync with the corresponding route’s model hook.
49+
50+
**Note:** this _only_ works if you do not mutate the `model` in either the `afterModel` or `setupController` hooks on the route! That's generally considered to be a bad practice anyway. If you do change the type there, you'll need to define the type in some other way and make sure your route's model is defined another way.
4951

50-
**Note:** this *only* works if you do not mutate the `model` in either the `afterModel` or `setupController` hooks on the route! That's generally considered to be a bad practice anyway. If you do change the type there, you'll need to define the type in some other way and make sure your route's model is defined another way.

docs/ember-data/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Working With Ember Data
2+

docs/ember-data/models.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
Ember Data models are normal TypeScript classes, but with properties decorated to define how the model represents an API resource and relationships to other resources. The decorators the library supplies "just work" with TypeScript at runtime, but require type annotations to be useful with TypeScript.
44

5-
For an overview of using Ember's decorators with TypeScript, see <LinkTo @route='docs.ts.decorators'>our overview</LinkTo>.
5+
For an overview of using Ember's decorators with TypeScript, see our overview.
66

77
## `@attr`
88

99
The type returned by the `@attr` decorator is whatever [Transform](https://api.emberjs.com/ember-data/release/classes/Transform) is applied via the invocation.
1010

11-
- If you supply no argument to `@attr`, the value is passed through without transformation.
12-
13-
- If you supply one of the built-in transforms, you will get back a corresponding type:
14-
- `@attr('string')``string`
15-
- `@attr(number)``number`,
16-
- `@attr('boolean')``boolean`
17-
- `@attr'date')``Date`
18-
19-
- If you supply a custom transform, you will get back the type returned by your transform.
11+
* If you supply no argument to `@attr`, the value is passed through without transformation.
12+
* If you supply one of the built-in transforms, you will get back a corresponding type:
13+
* `@attr('string')``string`
14+
* `@attr(number)``number`,
15+
* `@attr('boolean')``boolean`
16+
* `@attr'date')``Date`
17+
* If you supply a custom transform, you will get back the type returned by your transform.
2018

2119
So, for example, you might write a class like this:
2220

23-
```ts
21+
```typescript
2422
import Model, { attr } from '@ember-data/object';
2523
import CustomType from '../transforms/custom-transform';
2624

@@ -39,13 +37,13 @@ export default class User extends Model {
3937
}
4038
```
4139

42-
**Very important:** Even more than with decorators in general, you should be careful when deciding whether to mark a property as optional `?` or definitely present (no annotation): Ember Data will default to leaving a property empty if it is not supplied by the API or by a developer when creating it. That is: the *default* for Ember corresponds to an optional field on the model.
40+
**Very important:** Even more than with decorators in general, you should be careful when deciding whether to mark a property as optional `?` or definitely present \(no annotation\): Ember Data will default to leaving a property empty if it is not supplied by the API or by a developer when creating it. That is: the _default_ for Ember corresponds to an optional field on the model.
4341

44-
The *safest* type you can write for an Ember Data model, therefore, leaves every property optional: this is how models *actually* behave. If you choose to mark properties as definitely present by leaving off the `?`, you should take care to guarantee that this is a guarantee your API upholds, and that ever time you create a record from within the app, *you* uphold those guarantees.
42+
The _safest_ type you can write for an Ember Data model, therefore, leaves every property optional: this is how models _actually_ behave. If you choose to mark properties as definitely present by leaving off the `?`, you should take care to guarantee that this is a guarantee your API upholds, and that ever time you create a record from within the app, _you_ uphold those guarantees.
4543

4644
One way to make this safer is to supply a default value using the `defaultValue` on the options hash for the attribute:
4745

48-
```ts
46+
```typescript
4947
import Model, { attr } from '@ember-data/object';
5048

5149
export default class User extends Model {
@@ -62,15 +60,14 @@ export default class User extends Model {
6260

6361
## `@belongsTo`
6462

65-
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }` (which it is by default).
66-
67-
- If the value is `true`, the type you should use is `DS.PromiseObject<Model>`, where `Model` is the type of the model you are creating a relationship to.
63+
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }` \(which it is by default\).
6864

69-
- If the value is `false`, the type is `Model`, where `Model` is the type of the model you are creating a relationship to.
65+
* If the value is `true`, the type you should use is `DS.PromiseObject<Model>`, where `Model` is the type of the model you are creating a relationship to.
66+
* If the value is `false`, the type is `Model`, where `Model` is the type of the model you are creating a relationship to.
7067

7168
So, for example, you might define a class like this:
7269

73-
```ts
70+
```typescript
7471
import Model, { belongsTo } from '@ember-data/model';
7572
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
7673
import User from './user';
@@ -85,24 +82,23 @@ export default class Post extends Model {
8582
}
8683
```
8784

88-
These are *type*-safe to define as always present, that is to leave off the `?` optional marker:
85+
These are _type_-safe to define as always present, that is to leave off the `?` optional marker:
8986

90-
- accessing an async relationship will always return a `PromiseObject`, which itself may or may not ultimately resolve to a value—depending on the API response—but will always be present itself.
91-
- accessing a non-async relationship which is known to be associated but has not been loaded will trigger an error, so all access to the property will be safe *if* it resolves at all.
87+
* accessing an async relationship will always return a `PromiseObject`, which itself may or may not ultimately resolve to a value—depending on the API response—but will always be present itself.
88+
* accessing a non-async relationship which is known to be associated but has not been loaded will trigger an error, so all access to the property will be safe _if_ it resolves at all.
9289

93-
Note, however, that this type-safety is not a guarantee of there being no runtime error: you still need to uphold the contract for non-async relationships (that is: loading the data first, or side-loading it with the request) to avoid throwing an error!
90+
Note, however, that this type-safety is not a guarantee of there being no runtime error: you still need to uphold the contract for non-async relationships \(that is: loading the data first, or side-loading it with the request\) to avoid throwing an error!
9491

9592
## `@hasMany`
9693

97-
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }` (which it is by default).
94+
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }` \(which it is by default\).
9895

99-
- If the value is `true`, the type you should use is `DS.PromiseManyArray<Model>`, where `Model` is the type of the model you are creating a relationship to.
100-
101-
- If the value is `false`, the type is `EmberArray<Model>`, where `Model` is the type of the model you are creating a relationship to.
96+
* If the value is `true`, the type you should use is `DS.PromiseManyArray<Model>`, where `Model` is the type of the model you are creating a relationship to.
97+
* If the value is `false`, the type is `EmberArray<Model>`, where `Model` is the type of the model you are creating a relationship to.
10298

10399
So, for example, you might define a class like this:
104100

105-
```ts
101+
```typescript
106102
import Model, { hasMany } from '@ember-data/model';
107103
import EmberArray from '@ember/array';
108104
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
@@ -118,10 +114,11 @@ export default class Thread extends Model {
118114
}
119115
```
120116

121-
The same basic rules about the safety of these lookups as with `@belongsTo` apply to these types. The difference is just that in `@hasMany` the resulting types are *arrays* rather than single objects.
117+
The same basic rules about the safety of these lookups as with `@belongsTo` apply to these types. The difference is just that in `@hasMany` the resulting types are _arrays_ rather than single objects.
122118

123119
## Importing `PromiseObject` and `PromiseManyArray`
124120

125-
There is no public import path in the [Ember Data Packages](https://emberjs.github.io/rfcs/0395-ember-data-packages.html) API for the `PromiseObject` and `PromiseManyArray` types. These types are slowly being disentangled from Ember Data and will eventually be removed. However, until they are, we need a way to refer to them. For *now*, the best option is to refer to them via the legacy `DS` import.
121+
There is no public import path in the [Ember Data Packages](https://emberjs.github.io/rfcs/0395-ember-data-packages.html) API for the `PromiseObject` and `PromiseManyArray` types. These types are slowly being disentangled from Ember Data and will eventually be removed. However, until they are, we need a way to refer to them. For _now_, the best option is to refer to them via the legacy `DS` import.
126122

127123
In the future, they will become unnecesary, as the types will simply be `Promise<Model>` and `Promise<Array<Model>>`.
124+

docs/ember-data/overview.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Overview: Ember Data
22

3-
In this section, we cover how to use TypeScript effectively with specific Ember Data APIs (anything you'd find under the `@ember-data` package namespace).
3+
In this section, we cover how to use TypeScript effectively with specific Ember Data APIs \(anything you'd find under the `@ember-data` package namespace\).
4+
5+
We do _not_ cover general usage of Ember Data; instead, we assume that as background knowledge. Please see the Ember Data [Guides](https://guides.emberjs.com/release/models) and [API docs](https://api.emberjs.com/ember-data/release)!
46

5-
We do *not* cover general usage of Ember Data; instead, we assume that as background knowledge. Please see the Ember Data [Guides](https://guides.emberjs.com/release/models) and [API docs](https://api.emberjs.com/ember-data/release)!

docs/ember/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Working With Ember
2+

0 commit comments

Comments
 (0)