Skip to content

Conversation

@brandongregoryscott
Copy link
Contributor

@brandongregoryscott brandongregoryscott commented Jun 20, 2021

Resolves #129 AuditableDefaultValues / Factory for requiring properties to be set

  • defaultValuesFactory which essentially just provides typing to ensure consumer doesn't miss any properties of type T
  • auditableDefaultValuesFactory which does the same, but also provides defined properties for Auditables
  • ensureRecords which takes an array of objects and maps it through ensureRecord, which is common for view model constructors to do for navigation properties
  • Some additional cleanup, dependency bumps and removal of ported types

  • Related GitHub issue(s) linked in PR description
  • Destination branch merged, built and tested with your changes
  • Code formatted and follows best practices and patterns
  • Code builds cleanly (no additional warnings or errors)
  • Manually tested
  • Automated tests are passing
  • No decreases in automated test coverage
  • Documentation updated (readme, docs, comments, etc.)
  • [-] Localization: No hard-coded error messages in code files (minimally in string constants)

@brandongregoryscott brandongregoryscott added enhancement New feature or request dependencies Pull requests that update a dependency file labels Jun 20, 2021
@brandongregoryscott brandongregoryscott requested review from a team and wintondeshong June 20, 2021 18:37
Copy link
Contributor

@myty myty left a 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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful type! 👏🏻

* @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[] {
Copy link
Contributor

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[]

Copy link
Contributor Author

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 👍

@dylanjustice
Copy link
Contributor

Love the ensureRecords addition. That will come in handy.

@brandongregoryscott brandongregoryscott merged commit b2b306d into rsm-hcd:main Jun 22, 2021
@brandongregoryscott brandongregoryscott deleted the feature/default-values-factory branch June 22, 2021 12:35
@brandongregoryscott
Copy link
Contributor Author

@all-contributors add @dylanjustice for review

@allcontributors
Copy link
Contributor

@brandongregoryscott

I've put up a pull request to add @dylanjustice! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AuditableDefaultValues / Factory for requiring properties to be set

3 participants