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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-cherries-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-stuff-core": minor
---

Add Without, Nullable, and TSFixMe helper types
25 changes: 25 additions & 0 deletions packages/wonder-stuff-core/src/types.ts
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?

Original file line number Diff line number Diff line change
Expand Up @@ -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`.

*/
export type Without<C, R> = Omit<C, keyof R>;
Comment on lines +41 to +44
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.


/**
* Opposite of `NonNullable<T>`.
*
* This type is most useful in making code that's been converted from Flow
* to TypeScript more readable.
*/
export type Nullable<T> = T | null | undefined;

/**
* This type can be used in place of `any` to indicate that we don't know
* what the type is, but we know that it is wrong and needs to be fixed.
*
* It's similar to $FlowFixMe in Flow.
*
* This should be used in situations where `@ts-expect-error` cannot be used
* or should not be used (as is the case with type errors on props in JSX
* elements).
*/
export type TSFixMe<Message extends string = string> = Message & any;