Skip to content

Commit 1f7514f

Browse files
authored
Add a code sample to new import type recommendation
1 parent 1db431c commit 1f7514f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/ember-data/models.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ 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-
One should be certain to make use of [type-only imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html), available since TypeScript 3.8, and write `import type User from './user';`.
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:
66+
67+
```ts
68+
import type User from './user';
69+
```
6670

6771
### `@belongsTo`
6872

0 commit comments

Comments
 (0)