Skip to content
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

Refactoring: Simplify adding new configuration properties #2107

Merged
merged 2 commits into from Jan 31, 2024

Conversation

henrymercer
Copy link
Contributor

This PR refactors the way we initialize and test configurations to make it easier to add new configuration properties. It shouldn't have any user visible effects. Specifically, adding a new configuration property should not require updating irrelevant tests.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

This eliminates argument order mistakes, and also lets us add new inputs
without having to update every test.
This means that we don't need to update irrelevant test cases when we
add a new configuration property.
@henrymercer henrymercer requested a review from a team as a code owner January 30, 2024 19:02
src/testing-utils.ts Dismissed Show dismissed Hide dismissed
Copy link
Contributor

@angelapwen angelapwen left a comment

Choose a reason for hiding this comment

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

Just a quick question 😄

logger: Logger;
}

type GetDefaultConfigInputs = Omit<
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about the Omit type 🤯

Copy link
Contributor

Choose a reason for hiding this comment

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

We could use Omit/Pick to refactor the StatusReportBase and all those other interfaces later, perhaps...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are quite a few of these nice types :) https://www.typescriptlang.org/docs/handbook/utility-types.html

"configFile" | "configInput"
>;

type LoadConfigInputs = Omit<InitConfigInputs, "configInput"> & {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this & operator do here? Thought it represented bitwise AND but I can't really make sense of it in this context.

Copy link
Contributor

Choose a reason for hiding this comment

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

These are intersections. Though I wonder if this should be a union type (using |).

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 believe we want intersections, i.e. we want the type to include the properties from both the left hand side and the right hand side. For instance if we have (1) { a: 1 } and (2) { a: 1, b: "abc" }, then (1) and (2) would satisfy { a: int } | { b: string } but only (2) would satisfy { a: int } & { b: string }.

@henrymercer henrymercer merged commit e345133 into main Jan 31, 2024
317 checks passed
@henrymercer henrymercer deleted the henrymercer/refactor-config branch January 31, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants