-
Notifications
You must be signed in to change notification settings - Fork 12
Immutable record default values utilities #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Immutable record default values utilities #130
Conversation
…rface/record, update testing deps
myty
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
| /** | ||
| * Omit all keys from `TSource` that intersect with `TExclusion` | ||
| */ | ||
| type OmitKeys<TSource, TExclusion> = Omit<TSource, keyof TExclusion>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful type! 👏🏻
src/utilities/record-utils.ts
Outdated
| * @param maybeRecords Array of objects or Records to be coalesced into Records. | ||
| * @param record Type of the Record to be instantiated | ||
| */ | ||
| ensureRecords<T>(maybeRecords: any[], record: Constructor<T>): T[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought: What if this was more strongly typed? Something like this:
ensureRecords<TValue, TRecord extends TValue>(
maybeRecords: TValue[],
record: Constructor<TRecord>
): TRecord[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why it couldn't be - let me try it out 👍
|
Love the |
|
@all-contributors add @dylanjustice for review |
|
I've put up a pull request to add @dylanjustice! 🎉 |
Resolves #129 AuditableDefaultValues / Factory for requiring properties to be set
defaultValuesFactorywhich essentially just provides typing to ensure consumer doesn't miss any properties of typeTauditableDefaultValuesFactorywhich does the same, but also provides defined properties forAuditablesensureRecordswhich takes an array of objects and maps it throughensureRecord, which is common for view model constructors to do for navigation properties