@depup/type-fest 5.5.0-depup.0 → 5.9.0-depup.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 (117) hide show
  1. package/README.md +2 -2
  2. package/changes.json +1 -1
  3. package/index.d.ts +16 -8
  4. package/package.json +8 -6
  5. package/readme.md +85 -61
  6. package/source/absolute.d.ts +52 -0
  7. package/source/all-extend.d.ts +6 -4
  8. package/source/all-union-fields.d.ts +18 -18
  9. package/source/and.d.ts +1 -1
  10. package/source/array-reverse.d.ts +4 -3
  11. package/source/array-splice.d.ts +24 -24
  12. package/source/array-tail.d.ts +4 -4
  13. package/source/camel-case.d.ts +38 -5
  14. package/source/camel-cased-properties-deep.d.ts +11 -4
  15. package/source/camel-cased-properties.d.ts +5 -1
  16. package/source/conditional-keys.d.ts +1 -1
  17. package/source/delimiter-case.d.ts +11 -9
  18. package/source/delimiter-cased-properties-deep.d.ts +8 -1
  19. package/source/delimiter-cased-properties.d.ts +5 -1
  20. package/source/empty-object.d.ts +1 -1
  21. package/source/entries.d.ts +1 -1
  22. package/source/entry.d.ts +1 -1
  23. package/source/exclude-exactly.d.ts +11 -11
  24. package/source/exclude-rest-element.d.ts +4 -4
  25. package/source/exclusify-union.d.ts +4 -4
  26. package/source/extends-strict.d.ts +129 -22
  27. package/source/extract-exactly.d.ts +56 -0
  28. package/source/get.d.ts +1 -1
  29. package/source/greater-than.d.ts +3 -2
  30. package/source/has-optional-keys.d.ts +1 -1
  31. package/source/has-readonly-keys.d.ts +1 -1
  32. package/source/has-required-keys.d.ts +1 -1
  33. package/source/has-writable-keys.d.ts +1 -1
  34. package/source/int-closed-range.d.ts +1 -3
  35. package/source/int-range.d.ts +3 -5
  36. package/source/internal/array.d.ts +8 -8
  37. package/source/internal/keys.d.ts +9 -9
  38. package/source/internal/numeric.d.ts +19 -27
  39. package/source/internal/object.d.ts +44 -6
  40. package/source/internal/string.d.ts +1 -76
  41. package/source/internal/tuple.d.ts +2 -2
  42. package/source/internal/type.d.ts +16 -10
  43. package/source/is-boolean-literal.d.ts +39 -0
  44. package/source/is-integer.d.ts +8 -8
  45. package/source/is-literal.d.ts +43 -267
  46. package/source/is-numeric-literal.d.ts +50 -0
  47. package/source/is-string-literal.d.ts +72 -0
  48. package/source/is-symbol-literal.d.ts +39 -0
  49. package/source/is-union.d.ts +12 -12
  50. package/source/iterable-element.d.ts +5 -5
  51. package/source/jsonify.d.ts +5 -9
  52. package/source/kebab-case.d.ts +1 -0
  53. package/source/kebab-cased-properties-deep.d.ts +7 -0
  54. package/source/kebab-cased-properties.d.ts +5 -1
  55. package/source/keys-of-union.d.ts +2 -2
  56. package/source/last-array-element.d.ts +66 -13
  57. package/source/less-than-or-equal.d.ts +1 -1
  58. package/source/literal-to-primitive.d.ts +1 -1
  59. package/source/literal-union.d.ts +1 -1
  60. package/source/merge-exclusive.d.ts +3 -3
  61. package/source/multidimensional-array.d.ts +1 -1
  62. package/source/multidimensional-readonly-array.d.ts +1 -1
  63. package/source/non-nullable-deep.d.ts +102 -0
  64. package/source/numeric.d.ts +3 -3
  65. package/source/object-merge.d.ts +21 -16
  66. package/source/omit-deep.d.ts +22 -22
  67. package/source/or.d.ts +1 -1
  68. package/source/package-json.d.ts +7 -7
  69. package/source/partial-deep.d.ts +3 -1
  70. package/source/pascal-case.d.ts +1 -0
  71. package/source/pascal-cased-properties-deep.d.ts +7 -0
  72. package/source/pascal-cased-properties.d.ts +5 -1
  73. package/source/pick-deep.d.ts +2 -0
  74. package/source/readonly-deep.d.ts +5 -3
  75. package/source/remove-prefix.d.ts +16 -34
  76. package/source/remove-suffix.d.ts +114 -0
  77. package/source/rename-keys.d.ts +163 -0
  78. package/source/replace.d.ts +2 -2
  79. package/source/require-all-or-none.d.ts +5 -5
  80. package/source/require-at-least-one.d.ts +9 -11
  81. package/source/require-exactly-one.d.ts +7 -7
  82. package/source/require-one-or-none.d.ts +5 -5
  83. package/source/required-deep.d.ts +3 -1
  84. package/source/schema.d.ts +16 -8
  85. package/source/screaming-snake-case.d.ts +1 -0
  86. package/source/set-non-nullable-deep.d.ts +8 -4
  87. package/source/set-non-nullable.d.ts +1 -1
  88. package/source/set-optional.d.ts +5 -5
  89. package/source/set-readonly.d.ts +3 -3
  90. package/source/set-required-deep.d.ts +3 -2
  91. package/source/set-required.d.ts +3 -3
  92. package/source/shared-union-fields-deep.d.ts +4 -3
  93. package/source/shared-union-fields.d.ts +9 -9
  94. package/source/snake-case.d.ts +1 -0
  95. package/source/snake-cased-properties-deep.d.ts +7 -0
  96. package/source/snake-cased-properties.d.ts +5 -1
  97. package/source/some-extend.d.ts +6 -4
  98. package/source/split-on-rest-element.d.ts +6 -4
  99. package/source/split.d.ts +1 -1
  100. package/source/string-length.d.ts +38 -0
  101. package/source/string-repeat.d.ts +48 -21
  102. package/source/string-slice.d.ts +1 -1
  103. package/source/string-to-array.d.ts +97 -0
  104. package/source/string-to-number.d.ts +67 -0
  105. package/source/subtract.d.ts +4 -3
  106. package/source/sum.d.ts +5 -4
  107. package/source/tagged.d.ts +3 -5
  108. package/source/tsconfig-json.d.ts +40 -8
  109. package/source/tuple-of.d.ts +42 -8
  110. package/source/typed-array.d.ts +1 -0
  111. package/source/union-length.d.ts +27 -0
  112. package/source/union-to-intersection.d.ts +1 -1
  113. package/source/union-to-tuple.d.ts +8 -4
  114. package/source/unwrap-required.d.ts +37 -0
  115. package/source/words.d.ts +30 -4
  116. package/source/writable.d.ts +14 -14
  117. package/source/xor.d.ts +1 -1
@@ -16,6 +16,7 @@ import type {SnakeCase} from 'type-fest';
16
16
  const someVariable: SnakeCase<'fooBar'> = 'foo_bar';
17
17
  const noSplitOnNumbers: SnakeCase<'p2pNetwork'> = 'p2p_network';
18
18
  const splitOnNumbers: SnakeCase<'p2pNetwork', {splitOnNumbers: true}> = 'p_2_p_network';
19
+ const splitOnPunctuation: SnakeCase<'div.card::after', {splitOnPunctuation: true}> = 'div_card_after';
19
20
 
20
21
  // Advanced
21
22
 
@@ -51,6 +51,13 @@ const splitOnNumbers: SnakeCasedPropertiesDeep<{line1: {line2: [{line3: string}]
51
51
  ],
52
52
  },
53
53
  };
54
+
55
+ const splitOnPunctuation: SnakeCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
56
+ 'user_info': {
57
+ 'user_id': 1,
58
+ 'user_name': 'Tom',
59
+ },
60
+ };
54
61
  ```
55
62
 
56
63
  @category Change case
@@ -4,7 +4,7 @@ import type {ApplyDefaultOptions} from './internal/index.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
- Convert object properties to snake case but not recursively.
7
+ Convert top-level object properties to snake case.
8
8
 
9
9
  This can be useful when, for example, converting some API types from a different style.
10
10
 
@@ -28,6 +28,10 @@ const result: SnakeCasedProperties<User> = {
28
28
  const splitOnNumbers: SnakeCasedProperties<{line1: string}, {splitOnNumbers: true}> = {
29
29
  'line_1': 'string',
30
30
  };
31
+
32
+ const splitOnPunctuation: SnakeCasedProperties<{'foo::bar': string}, {splitOnPunctuation: true}> = {
33
+ 'foo_bar': 'string',
34
+ };
31
35
  ```
32
36
 
33
37
  @category Change case
@@ -97,8 +97,8 @@ type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
97
97
  export type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> =
98
98
  _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
99
99
 
100
- type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray,
101
- TArray extends readonly [infer First, ...infer Rest]
100
+ type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, {
101
+ ifNot: TArray extends readonly [infer First, ...infer Rest]
102
102
  ? IsNever<First> extends true
103
103
  ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true
104
104
  // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
@@ -107,7 +107,9 @@ type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<Som
107
107
  : First extends Type
108
108
  ? true
109
109
  : _SomeExtend<Rest, Type, Options>
110
- : false,
111
- false, false>;
110
+ : false;
111
+ ifAny: false;
112
+ ifNever: false;
113
+ }>;
112
114
 
113
115
  export {};
@@ -65,10 +65,12 @@ export type SplitOnRestElement<
65
65
  Options extends SplitOnRestElementOptions = {},
66
66
  > =
67
67
  Array_ extends unknown // For distributing `Array_`
68
- ? IfNotAnyOrNever<Array_, _SplitOnRestElement<
69
- Array_,
70
- ApplyDefaultOptions<SplitOnRestElementOptions, DefaultSplitOnRestElementOptions, Options>
71
- >> extends infer Result extends UnknownArray
68
+ ? IfNotAnyOrNever<Array_, {
69
+ ifNot: _SplitOnRestElement<
70
+ Array_,
71
+ ApplyDefaultOptions<SplitOnRestElementOptions, DefaultSplitOnRestElementOptions, Options>
72
+ >;
73
+ }> extends infer Result extends UnknownArray
72
74
  ? If<IsArrayReadonly<Array_>, Readonly<Result>, Result>
73
75
  : never // Should never happen
74
76
  : never; // Should never happen
package/source/split.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type {And} from './and.d.ts';
2
2
  import type {ApplyDefaultOptions, Not} from './internal/index.d.ts';
3
- import type {IsStringLiteral} from './is-literal.d.ts';
3
+ import type {IsStringLiteral} from './is-string-literal.d.ts';
4
4
  import type {Or} from './or.d.ts';
5
5
 
6
6
  /**
@@ -0,0 +1,38 @@
1
+ import type {StringToArray} from './string-to-array.d.ts';
2
+
3
+ /**
4
+ Returns the length of the given string.
5
+
6
+ @example
7
+ ```
8
+ import type {StringLength} from 'type-fest';
9
+
10
+ type A = StringLength<'abcde'>;
11
+ //=> 5
12
+
13
+ type B = StringLength<'abcde' | 'fgh'>;
14
+ //=> 3 | 5
15
+ ```
16
+
17
+ For non-literal strings, the result is `number` because the length of a non-literal string can be any number.
18
+
19
+ @example
20
+ ```
21
+ import type {StringLength} from 'type-fest';
22
+
23
+ type A = StringLength<string>;
24
+ //=> number
25
+
26
+ type B = StringLength<Uppercase<string>>;
27
+ //=> number
28
+
29
+ type C = StringLength<`${string}abc`>;
30
+ //=> number
31
+ ```
32
+
33
+ @category String
34
+ @category Template literal
35
+ */
36
+ export type StringLength<S extends string> = StringToArray<S>['length'];
37
+
38
+ export {};
@@ -1,5 +1,6 @@
1
- import type {IsNumericLiteral} from './is-literal.d.ts';
1
+ import type {IsNumericLiteral} from './is-numeric-literal.d.ts';
2
2
  import type {IsNegative} from './numeric.d.ts';
3
+ import type {DigitCharacter} from './characters.d.ts';
3
4
 
4
5
  /**
5
6
  Returns a new string which contains the specified number of copies of a given string, just like `String#repeat()`.
@@ -9,9 +10,9 @@ Returns a new string which contains the specified number of copies of a given st
9
10
  import type {StringRepeat} from 'type-fest';
10
11
 
11
12
  declare function stringRepeat<
12
- Input extends string,
13
+ S extends string,
13
14
  Count extends number,
14
- >(input: Input, count: Count): StringRepeat<Input, Count>;
15
+ >(input: S, count: Count): StringRepeat<S, Count>;
15
16
 
16
17
  // The return type is the exact string literal, not just `string`.
17
18
 
@@ -22,28 +23,54 @@ stringRepeat('=', 3);
22
23
  //=> '==='
23
24
  ```
24
25
 
26
+ Note: If the specified count has a decimal part, the decimal part will be ignored.
27
+
28
+ @example
29
+ ```
30
+ import type {StringRepeat} from 'type-fest';
31
+
32
+ type DecimalCount = StringRepeat<'foo', 2.5>;
33
+ //=> 'foofoo'
34
+ ```
35
+
25
36
  @category String
26
37
  @category Template literal
27
38
  */
28
- export type StringRepeat<
29
- Input extends string,
30
- Count extends number,
31
- > = StringRepeatHelper<Input, Count>;
32
-
33
- type StringRepeatHelper<
34
- Input extends string,
35
- Count extends number,
36
- Counter extends never[] = [],
37
- Accumulator extends string = '',
38
- > =
39
- IsNegative<Count> extends true
40
- ? never
41
- : Input extends ''
42
- ? ''
43
- : Count extends Counter['length']
44
- ? Accumulator
39
+ export type StringRepeat<S extends string, Count extends number> =
40
+ Count extends unknown // To distribute `Count`
41
+ ? IsNegative<Count> extends true
42
+ ? never
43
+ : S extends ''
44
+ ? ''
45
45
  : IsNumericLiteral<Count> extends false
46
46
  ? string
47
- : StringRepeatHelper<Input, Count, [...Counter, never], `${Accumulator}${Input}`>;
47
+ : `${Count}` extends `${string}e${string}`
48
+ ? string
49
+ : BuildStringDigitByDigit<S, `${Count}`>
50
+ : never;
51
+
52
+ type BuildStringDigitByDigit<S extends string, Count extends string, Accumulator extends string = ''> =
53
+ Count extends `${infer First extends DigitCharacter}${infer Rest}`
54
+ ? BuildStringDigitByDigit<
55
+ S,
56
+ Rest,
57
+ `${RepeatStringTenTimes<Accumulator>}${DigitStringRepeat<S, First>}`
58
+ >
59
+ : Accumulator;
60
+
61
+ type RepeatStringTenTimes<S extends string> = `${S}${S}${S}${S}${S}${S}${S}${S}${S}${S}`;
62
+
63
+ type DigitStringRepeat<S extends string, Digit extends DigitCharacter> = [
64
+ '',
65
+ `${S}`,
66
+ `${S}${S}`,
67
+ `${S}${S}${S}`,
68
+ `${S}${S}${S}${S}`,
69
+ `${S}${S}${S}${S}${S}`,
70
+ `${S}${S}${S}${S}${S}${S}`,
71
+ `${S}${S}${S}${S}${S}${S}${S}`,
72
+ `${S}${S}${S}${S}${S}${S}${S}${S}`,
73
+ `${S}${S}${S}${S}${S}${S}${S}${S}${S}`,
74
+ ][Digit];
48
75
 
49
76
  export {};
@@ -1,6 +1,6 @@
1
1
  import type {Join} from './join.d.ts';
2
2
  import type {ArraySlice} from './array-slice.d.ts';
3
- import type {StringToArray} from './internal/index.d.ts';
3
+ import type {StringToArray} from './string-to-array.d.ts';
4
4
 
5
5
  /**
6
6
  Returns a string slice of a given range, just like `String#slice()`.
@@ -0,0 +1,97 @@
1
+ import type {ApplyDefaultOptions} from './internal/object.d.ts';
2
+ import type {IfNotAnyOrNever} from './internal/type.d.ts';
3
+ import type {IsStringLiteral} from './is-string-literal.d.ts';
4
+ import type {Or} from './or.d.ts';
5
+
6
+ /**
7
+ @see {@link StringToArray}
8
+ */
9
+ export type StringToArrayOptions = {
10
+ /**
11
+ When enabled, non-literal parts of the string (e.g., `string`, `Uppercase<string>`) are mapped as single elements instead of being mapped as a rest element.
12
+
13
+ Note: Enabling this option can produce misleading results that might not reflect the actual runtime behavior.
14
+ For example, `StringToArray<string, {mapNonLiteralsDirectly: true}>` returns `[string]`, but at runtime, the string could be `'abc'` (which satisfies `string`), and converting it to an array would result in `['a', 'b', 'c']`, which doesn't satisfy `[string]`.
15
+
16
+ So, it is recommended to not enable this option unless you are aware of the implications.
17
+
18
+ @default false
19
+
20
+ @example
21
+ ```
22
+ import type {StringToArray} from 'type-fest';
23
+
24
+ type A = StringToArray<string, {mapNonLiteralsDirectly: false}>;
25
+ //=> string[]
26
+
27
+ type B = StringToArray<string, {mapNonLiteralsDirectly: true}>;
28
+ //=> [string]
29
+
30
+ type C = StringToArray<`on${string}`, {mapNonLiteralsDirectly: false}>;
31
+ //=> ['o', 'n', ...string[]]
32
+
33
+ type D = StringToArray<`on${string}`, {mapNonLiteralsDirectly: true}>;
34
+ //=> ['o', 'n', string]
35
+
36
+ type E = StringToArray<`${string}xyz`, {mapNonLiteralsDirectly: false}>;
37
+ //=> [...string[], 'x', 'y', 'z']
38
+
39
+ type F = StringToArray<`${string}xyz`, {mapNonLiteralsDirectly: true}>;
40
+ //=> [string, 'x', 'y', 'z']
41
+ ```
42
+ */
43
+ mapNonLiteralsDirectly?: boolean;
44
+ };
45
+
46
+ type DefaultStringToArrayOptions = {
47
+ mapNonLiteralsDirectly: false;
48
+ };
49
+
50
+ /**
51
+ Returns an array of the characters of the specified string.
52
+
53
+ @example
54
+ ```
55
+ import type {StringToArray} from 'type-fest';
56
+
57
+ type A = StringToArray<'abcde'>;
58
+ //=> ['a', 'b', 'c', 'd', 'e']
59
+
60
+ type B = StringToArray<''>;
61
+ //=> []
62
+
63
+ type C = StringToArray<string>;
64
+ //=> string[]
65
+
66
+ type D = StringToArray<`foo${string}bar`>;
67
+ //=> ['f', 'o', 'o', ...string[], 'b', 'a', 'r']
68
+
69
+ type E = StringToArray<`foo${string}bar`, {mapNonLiteralsDirectly: true}>;
70
+ //=> ['f', 'o', 'o', string, 'b', 'a', 'r']
71
+ ```
72
+
73
+ @see {@link StringToArrayOptions}
74
+
75
+ @category String
76
+ */
77
+ export type StringToArray<S extends string, Options extends StringToArrayOptions = {}> =
78
+ IfNotAnyOrNever<
79
+ S,
80
+ {
81
+ ifNot: _StringToArray<S, ApplyDefaultOptions<StringToArrayOptions, DefaultStringToArrayOptions, Options>>;
82
+ ifAny: unknown[];
83
+ }
84
+ >;
85
+
86
+ type _StringToArray<S extends string, Options extends Required<StringToArrayOptions>, Accumulator extends string[] = []> =
87
+ S extends `${infer First}${infer Rest}`
88
+ ? Or<IsStringLiteral<First>, Options['mapNonLiteralsDirectly']> extends true
89
+ ? _StringToArray<Rest, Options, [...Accumulator, First]>
90
+ : _StringToArray<Rest, Options, [...Accumulator, ...First[]]>
91
+ : S extends ''
92
+ ? Accumulator
93
+ : Options['mapNonLiteralsDirectly'] extends true
94
+ ? [...Accumulator, S]
95
+ : [...Accumulator, ...S[]];
96
+
97
+ export {};
@@ -0,0 +1,67 @@
1
+ import type {IfNotAnyOrNever} from './internal/type.d.ts';
2
+ import type {NegativeInfinity, PositiveInfinity} from './numeric.d.ts';
3
+
4
+ /**
5
+ Converts a numeric string to a number.
6
+
7
+ @example
8
+ ```
9
+ import type {StringToNumber} from 'type-fest';
10
+
11
+ type PositiveInteger = StringToNumber<'1234'>;
12
+ //=> 1234
13
+
14
+ type NegativeInteger = StringToNumber<'-1234'>;
15
+ //=> -1234
16
+
17
+ type PositiveFloat = StringToNumber<'1234.56'>;
18
+ //=> 1234.56
19
+
20
+ type NegativeFloat = StringToNumber<'-1234.56'>;
21
+ //=> -1234.56
22
+
23
+ type PositiveInfinity = StringToNumber<'Infinity'>;
24
+ //=> Infinity
25
+
26
+ type NegativeInfinity = StringToNumber<'-Infinity'>;
27
+ //=> -Infinity
28
+ ```
29
+
30
+ Note: Some strings, such as `'1.50'`, `'0b10'`, or `'12_345'`, may look like they can be converted to numbers, but they don't actually have corresponding numeric literals. So, in such cases, this type produces `never`. See [type-fest#1446](https://github.com/sindresorhus/type-fest/pull/1446) for more details.
31
+
32
+ @example
33
+ ```
34
+ import type {StringToNumber} from 'type-fest';
35
+
36
+ type FractionalsEndingInZero = StringToNumber<'1.50'>;
37
+ //=> never
38
+
39
+ type NonDecimalBases = StringToNumber<'0b10' | '0o10' | '0x10'>;
40
+ //=> never
41
+
42
+ type NumericSeparators = StringToNumber<'12_345'>;
43
+ //=> never
44
+ ```
45
+
46
+ @category String
47
+ @category Numeric
48
+ @category Template literal
49
+ */
50
+ export type StringToNumber<S extends string> = IfNotAnyOrNever<S, {ifNot: _StringToNumber<S>; ifAny: number}>;
51
+
52
+ type _StringToNumber<S extends string> =
53
+ S extends `${infer N extends number}`
54
+ ? number extends N
55
+ ? `${number}` extends S
56
+ ? N
57
+ : never
58
+ : N
59
+ : string extends S
60
+ ? number
61
+ : S extends 'Infinity'
62
+ ? PositiveInfinity
63
+ : S extends '-Infinity'
64
+ ? NegativeInfinity
65
+ : never;
66
+
67
+ export {};
@@ -1,7 +1,8 @@
1
- import type {NumberAbsolute, ReverseSign} from './internal/index.d.ts';
1
+ import type {ReverseSign} from './internal/index.d.ts';
2
2
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
3
3
  import type {LessThan} from './less-than.d.ts';
4
4
  import type {TupleOf} from './tuple-of.d.ts';
5
+ import type {Absolute} from './absolute.d.ts';
5
6
 
6
7
  /**
7
8
  Returns the difference between two numbers.
@@ -59,9 +60,9 @@ type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNeg
59
60
  ? SubtractPositives<A, B>
60
61
  : AreNegative extends [true, true]
61
62
  // When both numbers are negative we subtract the absolute values and then reverse the sign
62
- ? ReverseSign<SubtractPositives<NumberAbsolute<A>, NumberAbsolute<B>>>
63
+ ? ReverseSign<SubtractPositives<Absolute<A>, Absolute<B>>>
63
64
  // When the signs are different we can add the absolute values and then reverse the sign if A < B
64
- : [...TupleOf<NumberAbsolute<A>>, ...TupleOf<NumberAbsolute<B>>] extends infer R extends unknown[]
65
+ : [...TupleOf<Absolute<A>>, ...TupleOf<Absolute<B>>] extends infer R extends unknown[]
65
66
  ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length']
66
67
  : never;
67
68
 
package/source/sum.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type {TupleOf} from './tuple-of.d.ts';
2
- import type {NumberAbsolute, TupleMax, ReverseSign} from './internal/index.d.ts';
2
+ import type {TupleMax, ReverseSign} from './internal/index.d.ts';
3
3
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
4
4
  import type {Subtract} from './subtract.d.ts';
5
+ import type {Absolute} from './absolute.d.ts';
5
6
 
6
7
  /**
7
8
  Returns the sum of two numbers.
@@ -57,11 +58,11 @@ type SumPostChecks<A extends number, B extends number, AreNegative = [IsNegative
57
58
  ? SumPositives<A, B>
58
59
  : AreNegative extends [true, true]
59
60
  // When both numbers are negative we add the absolute values and then reverse the sign
60
- ? ReverseSign<SumPositives<NumberAbsolute<A>, NumberAbsolute<B>>>
61
+ ? ReverseSign<SumPositives<Absolute<A>, Absolute<B>>>
61
62
  // When the signs are different we can subtract the absolute values, remove the sign
62
63
  // and then reverse the sign if the larger absolute value is negative
63
- : NumberAbsolute<Subtract<NumberAbsolute<A>, NumberAbsolute<B>>> extends infer Result extends number
64
- ? TupleMax<[NumberAbsolute<A>, NumberAbsolute<B>]> extends infer Max_ extends number
64
+ : Absolute<Subtract<Absolute<A>, Absolute<B>>> extends infer Result extends number
65
+ ? TupleMax<[Absolute<A>, Absolute<B>]> extends infer Max_ extends number
65
66
  ? Max_ extends A | B
66
67
  // The larger absolute value is positive, so the result is positive
67
68
  ? Result
@@ -8,12 +8,10 @@ export type TagContainer<Token> = {
8
8
  type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{[K in Token]: TagMetadata}>;
9
9
 
10
10
  /**
11
- Attach a "tag" to an arbitrary type. This allows you to create distinct types, that aren't assignable to one another, for distinct concepts in your program that should not be interchangeable, even if their runtime values have the same type. (See examples.)
11
+ Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
12
12
 
13
13
  A type returned by `Tagged` can be passed to `Tagged` again, to create a type with multiple tags.
14
14
 
15
- [Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
16
-
17
15
  A tag's name is usually a string (and must be a string, number, or symbol), but each application of a tag can also contain an arbitrary type as its "metadata". See {@link GetTagMetadata} for examples and explanation.
18
16
 
19
17
  A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
@@ -100,7 +98,7 @@ const parsed = parse(x); // The type of `parsed` is { hello: string }
100
98
  export type GetTagMetadata<Type extends Tag<TagName, unknown>, TagName extends PropertyKey> = Type[typeof tag][TagName];
101
99
 
102
100
  /**
103
- Revert a tagged type back to its original type by removing all tags.
101
+ Get the untagged portion of a tagged type created with `Tagged`.
104
102
 
105
103
  Why is this necessary?
106
104
 
@@ -129,7 +127,7 @@ type WontWork = UnwrapTagged<string>;
129
127
  @category Type
130
128
  */
131
129
  export type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> =
132
- RemoveAllTags<TaggedType>;
130
+ RemoveAllTags<TaggedType>;
133
131
 
134
132
  type RemoveAllTags<T> = T extends Tag<PropertyKey, any>
135
133
  ? {
@@ -61,6 +61,7 @@ export namespace TsConfigJson {
61
61
  | 'ES2022'
62
62
  | 'ES2023'
63
63
  | 'ES2024'
64
+ | 'ES2025'
64
65
  | 'ESNext'
65
66
  // Lowercase alternatives
66
67
  | 'es3'
@@ -76,6 +77,7 @@ export namespace TsConfigJson {
76
77
  | 'es2022'
77
78
  | 'es2023'
78
79
  | 'es2024'
80
+ | 'es2025'
79
81
  | 'esnext';
80
82
 
81
83
  type Lib =
@@ -148,6 +150,13 @@ export namespace TsConfigJson {
148
150
  | 'ES2024.Regexp'
149
151
  | 'ES2024.SharedMemory'
150
152
  | 'ES2024.String'
153
+ | 'ES2025'
154
+ | 'ES2025.Collection'
155
+ | 'ES2025.Float16'
156
+ | 'ES2025.Intl'
157
+ | 'ES2025.Iterator'
158
+ | 'ES2025.Promise'
159
+ | 'ES2025.RegExp'
151
160
  | 'ESNext'
152
161
  | 'ESNext.Array'
153
162
  | 'ESNext.AsyncIterable'
@@ -156,6 +165,7 @@ export namespace TsConfigJson {
156
165
  | 'ESNext.Decorators'
157
166
  | 'ESNext.Disposable'
158
167
  | 'ESNext.Error'
168
+ | 'ESNext.Float16'
159
169
  | 'ESNext.Intl'
160
170
  | 'ESNext.Iterator'
161
171
  | 'ESNext.Object'
@@ -163,6 +173,7 @@ export namespace TsConfigJson {
163
173
  | 'ESNext.Regexp'
164
174
  | 'ESNext.String'
165
175
  | 'ESNext.Symbol'
176
+ | 'ESNext.Temporal'
166
177
  | 'ESNext.WeakRef'
167
178
  | 'DOM'
168
179
  | 'DOM.AsyncIterable'
@@ -244,6 +255,13 @@ export namespace TsConfigJson {
244
255
  | 'es2024.regexp'
245
256
  | 'es2024.sharedmemory'
246
257
  | 'es2024.string'
258
+ | 'es2025'
259
+ | 'es2025.collection'
260
+ | 'es2025.float16'
261
+ | 'es2025.intl'
262
+ | 'es2025.iterator'
263
+ | 'es2025.promise'
264
+ | 'es2025.regexp'
247
265
  | 'esnext'
248
266
  | 'esnext.array'
249
267
  | 'esnext.asynciterable'
@@ -252,6 +270,7 @@ export namespace TsConfigJson {
252
270
  | 'esnext.decorators'
253
271
  | 'esnext.disposable'
254
272
  | 'esnext.error'
273
+ | 'esnext.float16'
255
274
  | 'esnext.intl'
256
275
  | 'esnext.iterator'
257
276
  | 'esnext.object'
@@ -259,6 +278,7 @@ export namespace TsConfigJson {
259
278
  | 'esnext.regexp'
260
279
  | 'esnext.string'
261
280
  | 'esnext.symbol'
281
+ | 'esnext.temporal'
262
282
  | 'esnext.weakref'
263
283
  | 'dom'
264
284
  | 'dom.asynciterable'
@@ -326,7 +346,7 @@ export namespace TsConfigJson {
326
346
  | 'legacy'
327
347
  | 'force';
328
348
 
329
- type IgnoreDeprecations = '5.0';
349
+ type IgnoreDeprecations = '5.0' | '6.0';
330
350
  }
331
351
 
332
352
  type CompilerOptions = {
@@ -479,7 +499,7 @@ export namespace TsConfigJson {
479
499
  /**
480
500
  Specify module code generation: 'None', 'CommonJS', 'AMD', 'System', 'UMD', 'ES6', 'ES2015' or 'ESNext'. Only 'AMD' and 'System' can be used in conjunction with `--outFile`. 'ES6' and 'ES2015' values may be used when targeting 'ES5' or lower.
481
501
 
482
- @default ['ES3', 'ES5'].includes(target) ? 'CommonJS' : 'ES6'
502
+ Default: `'ESNext'` since TypeScript 6.0, `['ES3', 'ES5'].includes(target) ? 'CommonJS' : 'ES6'` before.
483
503
  */
484
504
  module?: CompilerOptions.Module;
485
505
 
@@ -587,8 +607,17 @@ export namespace TsConfigJson {
587
607
  */
588
608
  skipLibCheck?: boolean;
589
609
 
610
+ /**
611
+ Enforce stable type ordering.
612
+
613
+ @default false
614
+ */
615
+ stableTypeOrdering?: boolean;
616
+
590
617
  /**
591
618
  Concatenate and emit output to single file.
619
+
620
+ @deprecated since TypeScript 6.0.
592
621
  */
593
622
  outFile?: string;
594
623
 
@@ -696,7 +725,7 @@ export namespace TsConfigJson {
696
725
  /**
697
726
  Specify ECMAScript target version.
698
727
 
699
- @default 'es3'
728
+ Default: Current-year ES version since TypeScript 6.0, `'es3'` before.
700
729
  */
701
730
  target?: CompilerOptions.Target;
702
731
 
@@ -776,7 +805,7 @@ export namespace TsConfigJson {
776
805
  /**
777
806
  Report error if failed to find a source file for a side effect import.
778
807
 
779
- @default false
808
+ Default: `true` since TypeScript 6.0, `false` before.
780
809
  */
781
810
  noUncheckedSideEffectImports?: boolean;
782
811
 
@@ -822,6 +851,8 @@ export namespace TsConfigJson {
822
851
 
823
852
  /**
824
853
  Base directory to resolve non-relative module names.
854
+
855
+ @deprecated since TypeScript 6.0.
825
856
  */
826
857
  baseUrl?: string;
827
858
 
@@ -944,7 +975,7 @@ export namespace TsConfigJson {
944
975
  /**
945
976
  Enable all strict type checking options.
946
977
 
947
- @default false
978
+ Default: `true` since TypeScript 6.0, `false` before.
948
979
  */
949
980
  strict?: boolean;
950
981
 
@@ -959,6 +990,7 @@ export namespace TsConfigJson {
959
990
  Provide full support for iterables in `for-of`, spread, and destructuring when targeting `ES5` or `ES3`.
960
991
 
961
992
  @default false
993
+ @deprecated since TypeScript 6.0.
962
994
  */
963
995
  downlevelIteration?: boolean;
964
996
 
@@ -1150,7 +1182,7 @@ export namespace TsConfigJson {
1150
1182
  /**
1151
1183
  Enable lib replacement.
1152
1184
 
1153
- @default true
1185
+ Default: `false` since TypeScript 6.0, `true` before.
1154
1186
  */
1155
1187
  libReplacement?: boolean;
1156
1188
  };
@@ -1234,7 +1266,7 @@ export namespace TsConfigJson {
1234
1266
  exclude?: string[];
1235
1267
 
1236
1268
  /**
1237
- Disable infering what types should be added based on filenames in a project.
1269
+ Disable inferring what types should be added based on filenames in a project.
1238
1270
  */
1239
1271
  disableFilenameBasedTypeAcquisition?: boolean;
1240
1272
  };
@@ -1266,7 +1298,7 @@ export namespace TsConfigJson {
1266
1298
  }
1267
1299
 
1268
1300
  /**
1269
- Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 3.7).
1301
+ Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
1270
1302
 
1271
1303
  @category File
1272
1304
  */