type-fest 2.12.2 → 2.14.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.
Files changed (70) hide show
  1. package/index.d.ts +5 -1
  2. package/package.json +4 -4
  3. package/readme.md +74 -2
  4. package/source/async-return-type.d.ts +2 -2
  5. package/source/asyncify.d.ts +3 -3
  6. package/source/camel-case.d.ts +3 -3
  7. package/source/camel-cased-properties-deep.d.ts +3 -1
  8. package/source/camel-cased-properties.d.ts +3 -1
  9. package/source/conditional-except.d.ts +4 -4
  10. package/source/conditional-keys.d.ts +3 -1
  11. package/source/conditional-pick.d.ts +3 -3
  12. package/source/delimiter-case.d.ts +2 -2
  13. package/source/delimiter-cased-properties-deep.d.ts +3 -1
  14. package/source/delimiter-cased-properties.d.ts +3 -1
  15. package/source/entries.d.ts +2 -2
  16. package/source/entry.d.ts +1 -1
  17. package/source/exact.d.ts +51 -0
  18. package/source/except.d.ts +2 -2
  19. package/source/fixed-length-array.d.ts +4 -1
  20. package/source/get.d.ts +4 -4
  21. package/source/includes.d.ts +2 -2
  22. package/source/internal.d.ts +10 -1
  23. package/source/invariant-of.d.ts +5 -1
  24. package/source/iterable-element.d.ts +6 -0
  25. package/source/join.d.ts +1 -1
  26. package/source/jsonify.d.ts +5 -1
  27. package/source/kebab-case.d.ts +2 -2
  28. package/source/kebab-cased-properties-deep.d.ts +3 -1
  29. package/source/kebab-cased-properties.d.ts +3 -1
  30. package/source/last-array-element.d.ts +1 -1
  31. package/source/literal-to-primitive.d.ts +1 -1
  32. package/source/literal-union.d.ts +2 -2
  33. package/source/merge-exclusive.d.ts +1 -1
  34. package/source/merge.d.ts +3 -3
  35. package/source/multidimensional-array.d.ts +2 -2
  36. package/source/multidimensional-readonly-array.d.ts +2 -2
  37. package/source/mutable.d.ts +3 -38
  38. package/source/numeric.d.ts +5 -5
  39. package/source/opaque.d.ts +34 -1
  40. package/source/package-json.d.ts +8 -8
  41. package/source/partial-deep.d.ts +2 -2
  42. package/source/pascal-case.d.ts +2 -2
  43. package/source/pascal-cased-properties-deep.d.ts +3 -1
  44. package/source/pascal-cased-properties.d.ts +3 -1
  45. package/source/promisable.d.ts +1 -1
  46. package/source/promise-value.d.ts +4 -4
  47. package/source/readonly-deep.d.ts +2 -2
  48. package/source/readonly-tuple.d.ts +41 -0
  49. package/source/remove-index-signature.d.ts +8 -2
  50. package/source/replace.d.ts +67 -0
  51. package/source/require-all-or-none.d.ts +1 -1
  52. package/source/require-at-least-one.d.ts +2 -2
  53. package/source/require-exactly-one.d.ts +1 -1
  54. package/source/schema.d.ts +1 -1
  55. package/source/screaming-snake-case.d.ts +4 -4
  56. package/source/set-optional.d.ts +3 -3
  57. package/source/set-required.d.ts +3 -3
  58. package/source/set-return-type.d.ts +1 -1
  59. package/source/simplify.d.ts +2 -2
  60. package/source/snake-case.d.ts +2 -2
  61. package/source/snake-cased-properties-deep.d.ts +3 -1
  62. package/source/snake-cased-properties.d.ts +3 -1
  63. package/source/split.d.ts +1 -1
  64. package/source/string-key-of.d.ts +1 -1
  65. package/source/stringified.d.ts +1 -1
  66. package/source/trim.d.ts +1 -1
  67. package/source/union-to-intersection.d.ts +2 -2
  68. package/source/value-of.d.ts +1 -1
  69. package/source/writable.d.ts +40 -0
  70. package/license +0 -1
@@ -1,5 +1,5 @@
1
- import {Except} from './except';
2
- import {Simplify} from './simplify';
1
+ import type {Except} from './except';
2
+ import type {Simplify} from './simplify';
3
3
 
4
4
  /**
5
5
  Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
@@ -8,7 +8,7 @@ Use-case: You want to define a single model where the only thing that changes is
8
8
 
9
9
  @example
10
10
  ```
11
- import {SetRequired} from 'type-fest';
11
+ import type {SetRequired} from 'type-fest';
12
12
 
13
13
  type Foo = {
14
14
  a?: number;
@@ -9,7 +9,7 @@ Use-case: You want to define a wrapped function that returns something different
9
9
 
10
10
  @example
11
11
  ```
12
- import {SetReturnType} from 'type-fest';
12
+ import type {SetReturnType} from 'type-fest';
13
13
 
14
14
  type MyFunctionThatCanThrow = (foo: SomeType, bar: unknown) => SomeOtherType;
15
15
 
@@ -3,7 +3,7 @@ Useful to flatten the type output to improve type hints shown in editors. And al
3
3
 
4
4
  @example
5
5
  ```
6
- import {Simplify} from 'type-fest';
6
+ import type {Simplify} from 'type-fest';
7
7
 
8
8
  type PositionProps = {
9
9
  top: number;
@@ -25,7 +25,7 @@ If the type definition must be an interface (perhaps it was defined in a third-p
25
25
 
26
26
  @example
27
27
  ```
28
- import {Simplify} from 'type-fest';
28
+ import type {Simplify} from 'type-fest';
29
29
 
30
30
  interface SomeInterface {
31
31
  foo: number;
@@ -1,4 +1,4 @@
1
- import {DelimiterCase} from './delimiter-case';
1
+ import type {DelimiterCase} from './delimiter-case';
2
2
 
3
3
  /**
4
4
  Convert a string literal to snake-case.
@@ -7,7 +7,7 @@ This can be useful when, for example, converting a camel-cased object property t
7
7
 
8
8
  @example
9
9
  ```
10
- import {SnakeCase} from 'type-fest';
10
+ import type {SnakeCase} from 'type-fest';
11
11
 
12
12
  // Simple
13
13
 
@@ -1,4 +1,4 @@
1
- import {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
1
+ import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
2
2
 
3
3
  /**
4
4
  Convert object properties to snake case recursively.
@@ -10,6 +10,8 @@ This can be useful when, for example, converting some API types from a different
10
10
 
11
11
  @example
12
12
  ```
13
+ import type {SnakeCasedPropertiesDeep} from 'type-fest';
14
+
13
15
  interface User {
14
16
  userId: number;
15
17
  userName: string;
@@ -1,4 +1,4 @@
1
- import {DelimiterCasedProperties} from './delimiter-cased-properties';
1
+ import type {DelimiterCasedProperties} from './delimiter-cased-properties';
2
2
 
3
3
  /**
4
4
  Convert object properties to snake case but not recursively.
@@ -10,6 +10,8 @@ This can be useful when, for example, converting some API types from a different
10
10
 
11
11
  @example
12
12
  ```
13
+ import type {SnakeCasedProperties} from 'type-fest';
14
+
13
15
  interface User {
14
16
  userId: number;
15
17
  userName: string;
package/source/split.d.ts CHANGED
@@ -5,7 +5,7 @@ Use-case: Defining the return type of a method like `String.prototype.split`.
5
5
 
6
6
  @example
7
7
  ```
8
- import {Split} from 'type-fest';
8
+ import type {Split} from 'type-fest';
9
9
 
10
10
  declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
11
11
 
@@ -9,7 +9,7 @@ Use-cases:
9
9
 
10
10
  @example
11
11
  ```
12
- import {StringKeyOf} from 'type-fest';
12
+ import type {StringKeyOf} from 'type-fest';
13
13
 
14
14
  type Foo = {
15
15
  1: number,
@@ -5,7 +5,7 @@ Use-case: Changing interface values to strings in order to use them in a form mo
5
5
 
6
6
  @example
7
7
  ```
8
- import {Stringified} from 'type-fest';
8
+ import type {Stringified} from 'type-fest';
9
9
 
10
10
  type Car {
11
11
  model: string;
package/source/trim.d.ts CHANGED
@@ -13,7 +13,7 @@ Remove leading and trailing spaces from a string.
13
13
 
14
14
  @example
15
15
  ```
16
- import {Trim} from 'type-fest';
16
+ import type {Trim} from 'type-fest';
17
17
 
18
18
  Trim<' foo '>
19
19
  //=> 'foo'
@@ -5,7 +5,7 @@ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/21
5
5
 
6
6
  @example
7
7
  ```
8
- import {UnionToIntersection} from 'type-fest';
8
+ import type {UnionToIntersection} from 'type-fest';
9
9
 
10
10
  type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
11
11
 
@@ -17,7 +17,7 @@ A more applicable example which could make its way into your library code follow
17
17
 
18
18
  @example
19
19
  ```
20
- import {UnionToIntersection} from 'type-fest';
20
+ import type {UnionToIntersection} from 'type-fest';
21
21
 
22
22
  class CommandOne {
23
23
  commands: {
@@ -13,7 +13,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438)
13
13
  }
14
14
 
15
15
  // main.ts
16
- import {ValueOf} from 'type-fest';
16
+ import type {ValueOf} from 'type-fest';
17
17
  import data = require('./data.json');
18
18
 
19
19
  export function getData(name: string): ValueOf<typeof data> {
@@ -0,0 +1,40 @@
1
+ import type {Except} from './except';
2
+ import type {Simplify} from './simplify';
3
+
4
+ /**
5
+ Create a type that strips `readonly` from all or some of an object's keys. Inverse of `Readonly<T>`.
6
+
7
+ This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
8
+
9
+ @example
10
+ ```
11
+ import type {Writable} from 'type-fest';
12
+
13
+ type Foo = {
14
+ readonly a: number;
15
+ readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
16
+ readonly c: boolean;
17
+ };
18
+
19
+ const writableFoo: Writable<Foo> = {a: 1, b: ['2'], c: true};
20
+ writableFoo.a = 3;
21
+ writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
22
+ writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
23
+
24
+ type SomeWritable = Writable<Foo, 'b' | 'c'>;
25
+ // type SomeWritable = {
26
+ // readonly a: number;
27
+ // b: readonly string[]; // It's now writable. The type of the property remains unaffected.
28
+ // c: boolean; // It's now writable.
29
+ // }
30
+ ```
31
+
32
+ @category Object
33
+ */
34
+ export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
35
+ Simplify<
36
+ // Pick just the keys that are not writable from the base type.
37
+ Except<BaseType, Keys> &
38
+ // Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key.
39
+ {-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
40
+ >;
package/license DELETED
@@ -1 +0,0 @@
1
- SPDX-License-Identifier: (MIT OR CC0-1.0)