Skip to content

Commit b0e8d71

Browse files
committed
docs: fix typos and replace use of attr()
Currently in the docs, `@attr() declare name?` is typed as `string`, and no example of `@attr('string')` is given. I'm not sure if showing in the documentation that not passing a transform to `@attr()` should explicitly default to string is the correct thing to do, but I definitely think we should model the use of `@attr('string')` in the code examples.
1 parent 262f40b commit b0e8d71

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/ember-data/models.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The type returned by the `@attr` decorator is whatever [Transform](https://api.e
1111
* If you supply no argument to `@attr`, the value is passed through without transformation.
1212
* If you supply one of the built-in transforms, you will get back a corresponding type:
1313
* `@attr('string')``string`
14-
* `@attr(number)``number`,
14+
* `@attr('number')``number`
1515
* `@attr('boolean')``boolean`
16-
* `@attr'date')``Date`
16+
* `@attr('date')``Date`
1717
* If you supply a custom transform, you will get back the type returned by your transform.
1818

1919
So, for example, you might write a class like this:
@@ -23,8 +23,8 @@ import Model, { attr } from '@ember-data/model';
2323
import CustomType from '../transforms/custom-transform';
2424

2525
export default class User extends Model {
26-
@attr()
27-
name?: string;
26+
@attr('string')
27+
declare name?: string;
2828

2929
@attr('number')
3030
declare age: number;
@@ -47,7 +47,7 @@ One way to make this safer is to supply a default value using the `defaultValue`
4747
import Model, { attr } from '@ember-data/model';
4848

4949
export default class User extends Model {
50-
@attr()
50+
@attr('string')
5151
declare name?: string;
5252

5353
@attr('number', { defaultValue: 13 })
@@ -62,7 +62,7 @@ export default class User extends Model {
6262

6363
Relationships between models in Ember Data rely on importing the related models, like `import User from './user';`. This, naturally, can cause a recursive loop, as `/app/models/post.ts` imports `User` from `/app/models/user.ts`, and `/app/models/user.ts` imports `Post` from `/app/models/post.ts`. Recursive importing triggers an [`import/no-cycle`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md) error from eslint.
6464

65-
To avoid these errors, use of [type-only imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html), available since TypeScript 3.8:
65+
To avoid these errors, use [type-only imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html), available since TypeScript 3.8:
6666

6767
```ts
6868
import type User from './user';

0 commit comments

Comments
 (0)