mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
The previous type for `Snapshot<K>` defaulted `K` to `any`, but with a type constraint for `K` that often resolves to `never`: any time the `ModelRegistry` has no entries. `any` is not assignable to `never`, so this always produces a type error with an empty registry. In general, users have gotten past this by either adding a model to the registry, if they are using Ember Data, or by removing the Ember Data types if they are *not* using Ember Data. Both eliminate the type error! However, the type is strictly *wrong*, and not just in a theoretical sense: it can and *will* break users who have an Ember addon or app which uses Ember Data in a composite TS project, because [TS resolves *all* `@types`][1] unless overridden. For the sub-projects which do not have any entry in the registry, they get the expected type error: "'any' does not satisfy the constraint 'never'". The appropriate default for `K` here is just `keyof ModelRegistry`: this resolves to `never` when `ModelRegistry` is empty, or the keys of the registry otherwise, which achieves the goal of users never having to specify the key manually. The generic becomes effectively an invisible implementation detail, as it should be. [1]: https://www.typescriptlang.org/v2/en/tsconfig#types |
||
|---|---|---|
| .. | ||
| adapters | ||
| serializers | ||
| test | ||
| transforms | ||
| types/registries | ||
| v2 | ||
| adapter.d.ts | ||
| attr.d.ts | ||
| index.d.ts | ||
| model.d.ts | ||
| OTHER_FILES.txt | ||
| relationships.d.ts | ||
| serializer.d.ts | ||
| store.d.ts | ||
| transform.d.ts | ||
| tsconfig.json | ||
| tslint.json | ||