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

Add moar helper types to wonder-stuff-core #905

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kevinbarabash
Copy link
Contributor

Summary:

A number of repos are defining the same or similar utility types. Let's bring them into wonder-stuff-core so that they're consistent across projects.

Test Plan:

N/A

@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2023

🦋 Changeset detected

Latest commit: f9d211f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@khanacademy/wonder-stuff-core Minor
@khanacademy/wonder-stuff-render-environment-jsdom Patch
@khanacademy/wonder-stuff-render-server Patch
@khanacademy/wonder-stuff-sentry Patch
@khanacademy/wonder-stuff-server Patch
@khanacademy/wonder-stuff-testing Patch
@khanacademy/wonder-stuff-ci Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kevinbarabash kevinbarabash self-assigned this Sep 18, 2023
@khan-actions-bot khan-actions-bot requested a review from a team September 18, 2023 21:06
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/frontend-infra for changes to .changeset/violet-cherries-clean.md, packages/wonder-stuff-core/src/types.ts

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@kevinbarabash kevinbarabash requested review from lillialexis and somewhatabstract and removed request for a team September 18, 2023 21:07
Comment on lines +41 to +44
/**
* Remove the keys in `R` from `C`.
*/
export type Without<C, R> = Omit<C, keyof R>;
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'm kind of questioning the usefulness of this type. It's used primarily in components that use HOCs in webapp. We only had a helper type before because Flow didn't have Omit. I kind of think we should just replace Without with Omit.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind either way. It's a nice, clear utility that drops the need for the extra keyof and saves 2 keystrokes. However, if we didn't have it, I wouldn't mind either - but then you have to go find replace all the uses. Is that worth it? I don't know.

I don't think it does any harm existing.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Merging #905 (f9d211f) into main (f1cfdeb) will not change coverage.
Report is 21 commits behind head on main.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #905   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           97        97           
  Lines         1393      1390    -3     
  Branches       359       343   -16     
=========================================
- Hits          1393      1390    -3     

see 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

@github-actions
Copy link
Contributor

Size Change: 0 B

Total Size: 4.67 kB

ℹ️ View Unchanged
Filename Size
packages/wonder-stuff-core/dist/browser/es/index.js 1.87 kB
packages/wonder-stuff-sentry/dist/browser/es/index.js 1.66 kB
packages/wonder-stuff-testing/dist/browser/es/index.js 1.13 kB

compressed-size-action

Copy link
Member

@lillialexis lillialexis 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 though I don't know if I can weigh in on Omit/Without

Copy link
Member

@somewhatabstract somewhatabstract left a comment

Choose a reason for hiding this comment

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

LGTM

Pushing back for changes so we can have some tests to verify these utility types work.

Comment on lines +41 to +44
/**
* Remove the keys in `R` from `C`.
*/
export type Without<C, R> = Omit<C, keyof R>;
Copy link
Member

Choose a reason for hiding this comment

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

I don't mind either way. It's a nice, clear utility that drops the need for the extra keyof and saves 2 keystrokes. However, if we didn't have it, I wouldn't mind either - but then you have to go find replace all the uses. Is that worth it? I don't know.

I don't think it does any harm existing.

@@ -37,3 +37,28 @@ export type Secrets = {readonly [key: string]: SecretString};
* Make a read-only type mutable.
*/
export type Mutable<T> = {-readonly [P in keyof T]: T[P]};

/**
* Remove the keys in `R` from `C`.
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: This feels a little inexact - perhaps:

Suggested change
* Remove the keys in `R` from `C`.
* Remove from `C` properties that have identical keys to those in `R`.

Copy link
Member

Choose a reason for hiding this comment

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

suggestion[change-requested]: Can you add types tests to verify these types are working as expected?

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.

4 participants