type-fest 2.3.0 → 2.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "2.3.0",
3
+ "version": "2.3.4",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -14,7 +14,7 @@
14
14
  "node": ">=12.20"
15
15
  },
16
16
  "scripts": {
17
- "test": "xo && tsd && tsc"
17
+ "test": "xo && tsd && tsc && node script/test/source-files-extension.js"
18
18
  },
19
19
  "files": [
20
20
  "index.d.ts",
@@ -1,3 +1,34 @@
1
+ import {IsEqual} from './internal';
2
+
3
+ /**
4
+ Filter out keys from an object.
5
+
6
+ Returns `never` if `Exclude` is strictly equal to `Key`.
7
+ Returns `never` if `Key` extends `Exclude`.
8
+ Returns `Key` otherwise.
9
+
10
+ @example
11
+ ```
12
+ type Filtered = Filter<'foo', 'foo'>;
13
+ //=> never
14
+ ```
15
+
16
+ @example
17
+ ```
18
+ type Filtered = Filter<'bar', string>;
19
+ //=> never
20
+ ```
21
+
22
+ @example
23
+ ```
24
+ type Filtered = Filter<'bar', 'foo'>;
25
+ //=> 'bar'
26
+ ```
27
+
28
+ @see {Except}
29
+ */
30
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
31
+
1
32
  /**
2
33
  Create a type from an object type without certain keys.
3
34
 
@@ -21,4 +52,6 @@ type FooWithoutA = Except<Foo, 'a' | 'c'>;
21
52
 
22
53
  @category Utilities
23
54
  */
24
- export type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
55
+ export type Except<ObjectType, KeysType extends keyof ObjectType> = {
56
+ [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
57
+ };
@@ -1,13 +1,4 @@
1
- /**
2
- Returns a boolean for whether the two given types are equal.
3
-
4
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
5
- */
6
- type IsEqual<T, U> =
7
- (<G>() => G extends T ? 1 : 2) extends
8
- (<G>() => G extends U ? 1 : 2)
9
- ? true
10
- : false;
1
+ import {IsEqual} from './internal';
11
2
 
12
3
  /**
13
4
  Returns a boolean for whether the given array includes the given item.
@@ -0,0 +1,11 @@
1
+ /**
2
+ Returns a boolean for whether the two given types are equal.
3
+
4
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
5
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
6
+ */
7
+ export type IsEqual<T, U> =
8
+ (<G>() => G extends T ? 1 : 2) extends
9
+ (<G>() => G extends U ? 1 : 2)
10
+ ? true
11
+ : false;
@@ -18,8 +18,10 @@ typeof lastOf(array);
18
18
  @category Template Literals
19
19
  */
20
20
  export type LastArrayElement<ValueType extends readonly unknown[]> =
21
- ValueType extends [infer ElementType]
21
+ ValueType extends readonly [infer ElementType]
22
22
  ? ElementType
23
- : ValueType extends [infer _, ...infer Tail]
24
- ? LastArrayElement<Tail>
25
- : never;
23
+ : ValueType extends readonly [infer _, ...infer Tail]
24
+ ? LastArrayElement<Tail>
25
+ : ValueType extends ReadonlyArray<infer ElementType>
26
+ ? ElementType
27
+ : never;
@@ -24,6 +24,4 @@ let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promi
24
24
 
25
25
  @category Utilities
26
26
  */
27
- export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
28
- ? {0: PromiseValue<Value>; 1: Value}[PromiseType extends Promise<unknown> ? 0 : 1]
29
- : Otherwise;
27
+ export type PromiseValue<PromiseType> = PromiseType extends PromiseLike<infer Value> ? PromiseValue<Value> : PromiseType;