Closed jr-litmot closed 1 year ago
That looks quiet nice. I would certainly welcome such a PR. Thanks!
I tried making this change, but I realized the Exclude involving Entity
doesn't quite produce the desired result, I think due to Entity
having some computed property names or perhaps the [key: string]
from EntityData
.
The following seems to work well, but without the ability to use an entity as the generic (which diminishes the usefulness):
export type SchemaDefinition<T> = Record<keyof T, FieldDefinition>
It seemed like a good idea at the time, but it would need a better implementation. I'll go ahead and close this issue for now.
Hi,
I'm using Redis OM 0.4.2. If we were to add generic type support to Schema and SchemaDefinition, we could create a schema like this:
The advantage gained would be autocompletion and validation of the schema definition key names. (Suppose the
Foo
entity interface is defined and used elsewhere in the project. IfFoo
's properties are changed without updating the schema definition [or vice-versa], a compile error is thrown.)Note that we wouldn't lose the ability to create schema instances in the current way. This would still work:
Proposed implementation:
Change SchemaDefinition in definitions.ts to:
Then change Schema in schema.ts like so:
If it seems acceptable, I'm willing to submit a PR.