-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: This feels a little inexact - perhaps:
Suggested change
|
||||||
*/ | ||||||
export type Without<C, R> = Omit<C, keyof R>; | ||||||
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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; |
There was a problem hiding this comment.
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?