Skip to content

Commit 1e340c2

Browse files
authored
Merge pull request #324 from typed-ember/mike-north-patch-1
fix(docs): update ember-data section for single-file registries
2 parents 51b7cb2 + 468de71 commit 1e340c2

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

README.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ The declarations and changes you need to add to your existing files are:
392392
// attribute declarations here, as usual
393393
}) {}
394394

395-
declare module 'ember-data' {
396-
interface ModelRegistry {
395+
declare module 'ember-data/types/registries/model' {
396+
export default interface ModelRegistry {
397397
'user-meta': UserMeta;
398398
}
399399
}
@@ -408,8 +408,8 @@ The declarations and changes you need to add to your existing files are:
408408
// properties and methods
409409
}
410410

411-
declare module 'ember-data' {
412-
interface AdapterRegistry {
411+
declare module 'ember-data/types/registries/adapter' {
412+
export default interface AdapterRegistry {
413413
'user-meta': UserMeta;
414414
}
415415
}
@@ -424,12 +424,29 @@ The declarations and changes you need to add to your existing files are:
424424
// properties and methods
425425
}
426426

427-
declare module 'ember-data' {
428-
interface SerializerRegistry {
427+
declare module 'ember-data/types/registries/serializer' {
428+
export default interface SerializerRegistry {
429429
'user-meta': UserMeta;
430430
}
431431
}
432432
```
433+
434+
435+
* Transforms
436+
437+
```ts
438+
import DS from 'ember-data';
439+
440+
export default class ColorTransform extends DS.Transform {
441+
// properties and methods
442+
}
443+
444+
declare module 'ember-data/types/registries/transform' {
445+
export default interface TransformRegistry {
446+
color: ColorTransform;
447+
}
448+
}
449+
```
433450

434451
In addition to the registry, note the oddly defined class for `DS.Model`s. This is because we need to set up the attribute bindings on the prototype (for a discussion of how and why this is different from class properties, see [Typing Your Ember, Update, Part 2][pt2]), but we cannot just use a `const` here because we need a named type—like a class!—to reference in the type registry and elsewhere in the app.
435452

@@ -442,16 +459,18 @@ Also notice that unlike with service and controller injections, there is no unsa
442459
```ts
443460
import DS from 'ember-data';
444461

445-
declare module 'ember-data' {
446-
interface ModelRegistry {
462+
declare module 'ember-data/types/registries/model' {
463+
export default interface ModelRegistry {
447464
[key: string]: DS.Model;
448465
}
449-
450-
interface AdapterRegistry {
466+
}
467+
declare module 'ember-data/types/registries/adapter' {
468+
export default interface AdapterRegistry {
451469
[key: string]: DS.Adapter;
452470
}
453-
454-
interface SerializerRegistry {
471+
}
472+
declare module 'ember-data/types/registries/serializer' {
473+
export default interface SerializerRegistry {
455474
[key: string]: DS.Serializer;
456475
}
457476
}
@@ -472,8 +491,8 @@ This happens because the types for Ember's _test_ tooling includes the types for
472491
**The fix:** add a declaration like this in a new file named `ember-data.d.ts` in your `types` directory:
473492

474493
```ts
475-
declare module 'ember-data' {
476-
interface ModelRegistry {
494+
declare module 'ember-data/types/registries/model' {
495+
export default interface ModelRegistry {
477496
[key: string]: any;
478497
}
479498
}

0 commit comments

Comments
 (0)