@mll-lab/js-utils 2.27.1 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { DeepPartial, Either, Exact, Maybe, MaybePromise, Modify, ValueOf } from './types';
1
+ import { DeepPartial, Either, Exact, KeyOfType, Maybe, MaybePromise, Modify, ValueOf } from './types';
2
2
  declare type Bar = {
3
3
  baz: number;
4
4
  };
@@ -12,6 +12,12 @@ export declare const modifiedType: Modify<Obj, {
12
12
  foo: number;
13
13
  }>;
14
14
  export declare function acceptsValueOf(v: ValueOf<Obj>): string | Bar;
15
+ declare type Foo = {
16
+ a: number;
17
+ b: string;
18
+ };
19
+ export declare const correctNumberKey: KeyOfType<Foo, number>;
20
+ export declare const wrongNumberKey: KeyOfType<Foo, number>;
15
21
  export declare const maybeAllowsNull: Maybe<number>;
16
22
  export declare const maybeAllowsUndefined: Maybe<number>;
17
23
  export declare const maybeAllowsT: Maybe<number>;
package/dist/types.d.ts CHANGED
@@ -8,6 +8,14 @@ export declare type MaybePromise<T> = T | Promise<T>;
8
8
  export declare type Modify<T, R> = Pick<T, Exclude<keyof T, keyof R>> & R;
9
9
  /** The missing counterpart to keyof. */
10
10
  export declare type ValueOf<T> = T[keyof T];
11
+ /**
12
+ * Extracts keys of the given type TObject that are of type TKeys.
13
+ *
14
+ * https://stackoverflow.com/a/49752227
15
+ */
16
+ export declare type KeyOfType<TObject, TKeys> = keyof {
17
+ [P in keyof TObject as TObject[P] extends TKeys ? P : never]: unknown;
18
+ };
11
19
  /** Add null and undefined to a type. */
12
20
  export declare type Maybe<T> = T | null | undefined;
13
21
  /** Only props that are contained in T but not U. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mll-lab/js-utils",
3
- "version": "2.27.1",
3
+ "version": "2.28.0",
4
4
  "main": "dist/index.common.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",