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

refactor: strong type for getFormHelpers name #1029

Merged
merged 1 commit into from
Apr 15, 2022

Conversation

greyscaled
Copy link
Contributor

@greyscaled greyscaled commented Apr 15, 2022

Summary:

Modify getFormHelpers so that only the keys of the generic form interface
can be passed in for name.

Details:

Keys of an object in TS can naturally be of string | number | symbol. I don't think
there's an easy way to re-genericize this helper and type things that gets around this,
so I took the simple path of throwing an Error on typeof !== "string".

Impact:

Minor improvement to dev experience using getFormHelpers (compile-time safety).

@greyscaled greyscaled requested a review from a team as a code owner April 15, 2022 17:31
@greyscaled greyscaled self-assigned this Apr 15, 2022
@codecov
Copy link

codecov bot commented Apr 15, 2022

Codecov Report

Merging #1029 (b007377) into main (88e30be) will decrease coverage by 0.22%.
The diff coverage is 33.33%.

@@            Coverage Diff             @@
##             main    #1029      +/-   ##
==========================================
- Coverage   67.54%   67.32%   -0.23%     
==========================================
  Files         259      259              
  Lines       15059    15061       +2     
  Branches      151      152       +1     
==========================================
- Hits        10172    10140      -32     
- Misses       3873     3899      +26     
- Partials     1014     1022       +8     
Flag Coverage Δ
unittest-go-macos-latest 53.58% <ø> (-0.24%) ⬇️
unittest-go-postgres- 66.53% <ø> (-0.12%) ⬇️
unittest-go-ubuntu-latest 56.12% <ø> (-0.28%) ⬇️
unittest-go-windows-2022 52.98% <ø> (-0.03%) ⬇️
unittest-js 68.10% <33.33%> (-0.10%) ⬇️
Impacted Files Coverage Δ
site/src/components/Form/index.ts 89.47% <33.33%> (-10.53%) ⬇️
pty/start_other.go 64.70% <0.00%> (-23.53%) ⬇️
peerbroker/dial.go 77.04% <0.00%> (-6.56%) ⬇️
cli/cliui/agent.go 77.19% <0.00%> (-5.27%) ⬇️
peer/conn.go 76.14% <0.00%> (-5.08%) ⬇️
coderd/parameter/compute.go 74.07% <0.00%> (-4.45%) ⬇️
cli/cliui/provisionerjob.go 76.42% <0.00%> (-2.15%) ⬇️
coderd/provisionerdaemons.go 62.95% <0.00%> (-1.03%) ⬇️
coderd/database/queries.sql.go 83.65% <0.00%> (-0.21%) ⬇️
provisioner/terraform/provision.go 68.54% <0.00%> (+0.43%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88e30be...b007377. Read the comment docs.

// getIn is a util function from Formik that gets at any depth of nesting, and is necessary for the types to work
export const getFormHelpers = <T>(form: FormikContextType<T>, name: keyof T, error?: string): FormHelpers => {
if (typeof name !== "string") {
throw new Error(`name must be type of string, instead received '${typeof name}'`)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if somehow this gets thrown in production?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a desirable case at this stage. We don't yet have an error boundary ported (#1013 ), but you'd hit that.

@greyscaled greyscaled merged commit cf8a20d into main Apr 15, 2022
@greyscaled greyscaled deleted the vapurrmaid/getFormHelpers branch April 15, 2022 20:31
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
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