@silverhand/essentials
Advanced tools
Comparing version
export declare const isObject: (object: unknown) => object is object; | ||
export declare const isKeyInObject: <Key extends string>(object: unknown, key: Key) => object is object & Record<Key, unknown>; | ||
/** | ||
* A utility type that removes all keys with `undefined` values from an object. | ||
* | ||
* Note: Optional keys with `undefined` values are not removed. | ||
* | ||
* @example | ||
* ```ts | ||
* type Foo = { a: string; b: number | undefined; c?: boolean }; | ||
* type Bar = RemoveUndefinedKeys<Foo>; | ||
* // Bar is { a: string; b: number; c?: boolean } | ||
* ``` | ||
*/ | ||
type RemoveUndefinedKeys<T> = { | ||
[Key in keyof T as T[Key] extends undefined ? never : Key]: Exclude<T[Key], undefined>; | ||
}; | ||
/** | ||
* Remove all keys with `undefined` values from an object. This function only | ||
@@ -11,2 +26,3 @@ * performs a shallow removal, i.e. it does not remove `undefined` values nested | ||
*/ | ||
export declare const removeUndefinedKeys: <T extends Record<string, unknown>>(object: T) => T; | ||
export declare const removeUndefinedKeys: <T extends object>(object: T) => RemoveUndefinedKeys<T>; | ||
export {}; |
@@ -14,2 +14,3 @@ // eslint-disable-next-line @typescript-eslint/ban-types | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types -- this is a utility function | ||
const removeUndefinedKeys = (object) => | ||
@@ -16,0 +17,0 @@ // eslint-disable-next-line no-restricted-syntax |
{ | ||
"name": "@silverhand/essentials", | ||
"version": "2.8.7", | ||
"version": "2.8.8", | ||
"description": "The missing essentials for TypeScript (and JavaScript).", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:silverhand-io/essentials.git", |
Sorry, the diff of this file is not supported yet
39438
1.7%907
2.02%