-
Notifications
You must be signed in to change notification settings - Fork 577
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
Introduce StrictKeyOmit
#2968
Introduce StrictKeyOmit
#2968
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 |
---|---|---|
|
@@ -188,3 +188,17 @@ export class XRPCInvalidResponseError extends XRPCError { | |
) | ||
} | ||
} | ||
|
||
type IsLiteralKey<K extends PropertyKey> = { | ||
string: string extends K ? 0 : 1 | ||
number: number extends K ? 0 : 1 | ||
symbol: symbol extends K ? 0 : 1 | ||
}[K extends string ? 'string' : K extends number ? 'number' : 'symbol'] | ||
Comment on lines
+192
to
+196
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. This isn't 100% complete. It might not handle index signatures with template literal types or string mappings (like In a sense, support for |
||
|
||
type LiteralKey<T> = keyof { | ||
[K in keyof T as IsLiteralKey<K> extends 1 ? K : never]: K | ||
} | ||
|
||
export type StrictKeyOmit<T, K extends LiteralKey<T>> = { | ||
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.
|
||
[K2 in keyof T as K2 extends K ? never : K2]: T[K2] | ||
} |
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.
There might be a better place for this utility type. I don't know where you keep things like this so I just shoved it here for now