type-fest 4.18.2 → 4.19.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.
package/index.d.ts CHANGED
@@ -61,6 +61,7 @@ export type {SetReturnType} from './source/set-return-type';
61
61
  export type {SetParameterType} from './source/set-parameter-type';
62
62
  export type {Asyncify} from './source/asyncify';
63
63
  export type {Simplify} from './source/simplify';
64
+ export type {SimplifyDeep} from './source/simplify-deep';
64
65
  export type {Jsonify} from './source/jsonify';
65
66
  export type {Jsonifiable} from './source/jsonifiable';
66
67
  export type {Schema} from './source/schema';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.18.2",
3
+ "version": "4.19.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
package/readme.md CHANGED
@@ -173,6 +173,7 @@ Click the type names for complete docs.
173
173
  - [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
174
174
  - [`SetParameterType`](source/set-parameter-type.d.ts) - Create a function that replaces some parameters with the given parameters.
175
175
  - [`Simplify`](source/simplify.d.ts) - Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
176
+ - [`SimplifyDeep`](source/simplify-deep.d.ts) - Deeply simplifies an object type.
176
177
  - [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
177
178
  - [`StringKeyOf`](source/string-key-of.d.ts) - Get keys of the given type as strings.
178
179
  - [`Schema`](source/schema.d.ts) - Create a deep version of another object type where property values are recursively replaced into a given value type.
@@ -1,3 +1,5 @@
1
+ import type {IfNever} from './if-never';
2
+
1
3
  /**
2
4
  Extract the keys from a type where the value type of the key extends the given `Condition`.
3
5
 
@@ -36,10 +38,10 @@ export type ConditionalKeys<Base, Condition> =
36
38
  [Key in keyof Base]-?:
37
39
  // Pick only keys with types extending the given `Condition` type.
38
40
  Base[Key] extends Condition
39
- // Retain this key since the condition passes.
40
- ? Key
41
+ // Retain this key
42
+ // If the value for the key extends never, only include it if `Condition` also extends never
43
+ ? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
41
44
  // Discard this key since the condition fails.
42
45
  : never;
43
-
44
46
  // Convert the produced object into a union type of the keys which passed the conditional test.
45
47
  }[keyof Base];
@@ -11,11 +11,7 @@ import type {
11
11
  } from './internal';
12
12
  import type {UnknownRecord} from './unknown-record';
13
13
  import type {EnforceOptional} from './enforce-optional';
14
-
15
- /**
16
- Deeply simplifies an object excluding iterables and functions. Used internally to improve the UX and accept both interfaces and type aliases as inputs.
17
- */
18
- export type SimplifyDeep<Type> = ConditionalSimplifyDeep<Type, Function | Iterable<unknown>, object>;
14
+ import type {SimplifyDeep} from './simplify-deep';
19
15
 
20
16
  /**
21
17
  Try to merge two record properties or return the source property value, preserving `undefined` properties values in both cases.
@@ -3,9 +3,9 @@ import type {ExactKey, IsArrayReadonly, NonRecursiveType, SetArrayAccess, ToStri
3
3
  import type {IsEqual} from './is-equal';
4
4
  import type {IsNever} from './is-never';
5
5
  import type {LiteralUnion} from './literal-union';
6
- import type {SimplifyDeep} from './merge-deep';
7
6
  import type {Paths} from './paths';
8
7
  import type {SharedUnionFieldsDeep} from './shared-union-fields-deep';
8
+ import type {SimplifyDeep} from './simplify-deep';
9
9
  import type {UnknownArray} from './unknown-array';
10
10
 
11
11
  /**
@@ -0,0 +1,51 @@
1
+ import type {ConditionalSimplifyDeep} from './conditional-simplify';
2
+
3
+ /**
4
+ Deeply simplifies an object type.
5
+
6
+ Useful to flatten the type output to improve type hints shown in editors.
7
+
8
+ @example
9
+ ```
10
+ import type {SimplifyDeep} from 'type-fest';
11
+
12
+ type Properties1 = {
13
+ height: number;
14
+ position: {
15
+ top: number;
16
+ bottom: number;
17
+ };
18
+ };
19
+
20
+ type Properties2 = {
21
+ width: number;
22
+ position: {
23
+ left: number;
24
+ right: number;
25
+ };
26
+ };
27
+
28
+ type Properties = Properties1 & Properties2;
29
+ // In your editor, hovering over `Props` will show the following:
30
+ //
31
+ // type Properties = Properties1 & Properties2;
32
+
33
+ type SimplifyDeepProperties = SimplifyDeep<Properties1 & Properties2>;
34
+ // But if wrapped in SimplifyDeep, hovering over `Props` will show a flattened object with all the properties:
35
+ //
36
+ // SimplifyDeepProperties = {
37
+ // height: number;
38
+ // width: number;
39
+ // position: {
40
+ // top: number;
41
+ // bottom: number;
42
+ // left: number;
43
+ // right: number;
44
+ // };
45
+ // };
46
+ ```
47
+
48
+ @see Simplify
49
+ @category Object
50
+ */
51
+ export type SimplifyDeep<Type> = ConditionalSimplifyDeep<Type, Function | Iterable<unknown>, object>;
@@ -52,7 +52,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
52
52
  ```
53
53
 
54
54
  @link https://github.com/microsoft/TypeScript/issues/15300
55
-
55
+ @see SimplifyDeep
56
56
  @category Object
57
57
  */
58
58
  export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};