@visulima/tsconfig 1.1.23 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## @visulima/tsconfig [1.2.0](https://github.com/visulima/visulima/compare/@visulima/tsconfig@1.1.23...@visulima/tsconfig@1.2.0) (2025-09-24)
2
+
3
+ ### Features
4
+
5
+ * **tsconfig:** added support for typescript 5.9 ([b107d4e](https://github.com/visulima/visulima/commit/b107d4ee8a1f6df34e8613b08a377786283c9ff0))
6
+
1
7
  ## @visulima/tsconfig [1.1.23](https://github.com/visulima/visulima/compare/@visulima/tsconfig@1.1.22...@visulima/tsconfig@1.1.23) (2025-09-23)
2
8
 
3
9
  ### Miscellaneous Chores
package/README.md CHANGED
@@ -101,7 +101,7 @@ const tsconfig = await readTsConfig("/Users/../Projects/visulima/packages/tsconf
101
101
  type TsConfigJson = object;
102
102
  ```
103
103
 
104
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1
104
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1
105
105
 
106
106
  Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 3.7).
107
107
 
@@ -113,7 +113,7 @@ Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs
113
113
  optional compileOnSave: boolean;
114
114
  ```
115
115
 
116
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1264
116
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1264
117
117
 
118
118
  Enable Compile-on-Save for this project.
119
119
 
@@ -123,7 +123,7 @@ Enable Compile-on-Save for this project.
123
123
  optional compilerOptions: CompilerOptions;
124
124
  ```
125
125
 
126
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1249
126
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1249
127
127
 
128
128
  Instructs the TypeScript compiler how to compile `.ts` files.
129
129
 
@@ -133,7 +133,7 @@ Instructs the TypeScript compiler how to compile `.ts` files.
133
133
  optional exclude: string[];
134
134
  ```
135
135
 
136
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1281
136
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1281
137
137
 
138
138
  Specifies a list of files to be excluded from compilation. The `exclude` property only affects the files included via the `include` property and not the `files` property.
139
139
 
@@ -145,7 +145,7 @@ Glob patterns require TypeScript version 2.0 or later.
145
145
  optional extends: string | string[];
146
146
  ```
147
147
 
148
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1269
148
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1269
149
149
 
150
150
  Path to base configuration file to inherit from.
151
151
 
@@ -155,7 +155,7 @@ Path to base configuration file to inherit from.
155
155
  optional files: string[];
156
156
  ```
157
157
 
158
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1274
158
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1274
159
159
 
160
160
  If no `files` or `include` property is present in a `tsconfig.json`, the compiler defaults to including all files in the containing directory and subdirectories except those specified by `exclude`. When a `files` property is specified, only those files and those specified by `include` are included.
161
161
 
@@ -165,7 +165,7 @@ If no `files` or `include` property is present in a `tsconfig.json`, the compile
165
165
  optional include: string[];
166
166
  ```
167
167
 
168
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1288
168
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1288
169
169
 
170
170
  Specifies a list of glob patterns that match files to be included in compilation.
171
171
 
@@ -177,7 +177,7 @@ If no `files` or `include` property is present in a `tsconfig.json`, the compile
177
177
  optional references: References[];
178
178
  ```
179
179
 
180
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1293
180
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1293
181
181
 
182
182
  Referenced projects.
183
183
 
@@ -187,7 +187,7 @@ Referenced projects.
187
187
  optional typeAcquisition: TypeAcquisition;
188
188
  ```
189
189
 
190
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1259
190
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1259
191
191
 
192
192
  Auto type (.d.ts) acquisition options for this project.
193
193
 
@@ -197,7 +197,7 @@ Auto type (.d.ts) acquisition options for this project.
197
197
  optional watchOptions: WatchOptions;
198
198
  ```
199
199
 
200
- Defined in: node\_modules/.pnpm/type-fest@4.41.0/node\_modules/type-fest/source/tsconfig-json.d.ts:1254
200
+ Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/tsconfig-json.d.ts:1254
201
201
 
202
202
  Instructs the TypeScript compiler how to watch files.
203
203
 
@@ -209,7 +209,7 @@ Instructs the TypeScript compiler how to watch files.
209
209
  function findTsConfig(cwd?, options?): Promise<TsConfigResult>;
210
210
  ```
211
211
 
212
- Defined in: [packages/tsconfig/src/find-tsconfig.ts:30](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/find-tsconfig.ts#L30)
212
+ Defined in: [packages/tsconfig/src/find-tsconfig.ts:30](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/find-tsconfig.ts#L30)
213
213
 
214
214
  An asynchronous function that retrieves the TSConfig by searching for the "tsconfig.json" first,
215
215
  second attempt is to look for the "jsconfig.json" file from a given current working directory.
@@ -219,7 +219,7 @@ second attempt is to look for the "jsconfig.json" file from a given current work
219
219
  ##### cwd?
220
220
 
221
221
  Optional. The current working directory from which to search for the "tsconfig.json" file.
222
- The type of `cwd` is `string`.
222
+ The type of `cwd` is `string`.
223
223
 
224
224
  `string` | `URL`
225
225
 
@@ -232,13 +232,13 @@ Optional. The current working directory from which to search for the "tsconfig.j
232
232
  `Promise`\<[`TsConfigResult`](#tsconfigresult)\>
233
233
 
234
234
  A `Promise` that resolves to the TSConfig result object.
235
- The return type of the function is `Promise<TsConfigResult>`.
235
+ The return type of the function is `Promise<TsConfigResult>`.
236
236
 
237
237
  #### Throws
238
238
 
239
239
  An `Error` when the "tsconfig.json" file is not found.
240
240
 
241
- ***
241
+ ---
242
242
 
243
243
  ### findTsConfigSync()
244
244
 
@@ -246,7 +246,7 @@ An `Error` when the "tsconfig.json" file is not found.
246
246
  function findTsConfigSync(cwd?, options?): TsConfigResult;
247
247
  ```
248
248
 
249
- Defined in: [packages/tsconfig/src/find-tsconfig.ts:69](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/find-tsconfig.ts#L69)
249
+ Defined in: [packages/tsconfig/src/find-tsconfig.ts:69](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/find-tsconfig.ts#L69)
250
250
 
251
251
  #### Parameters
252
252
 
@@ -262,7 +262,7 @@ Defined in: [packages/tsconfig/src/find-tsconfig.ts:69](https://github.com/visul
262
262
 
263
263
  [`TsConfigResult`](#tsconfigresult)
264
264
 
265
- ***
265
+ ---
266
266
 
267
267
  ### readTsConfig()
268
268
 
@@ -270,7 +270,7 @@ Defined in: [packages/tsconfig/src/find-tsconfig.ts:69](https://github.com/visul
270
270
  function readTsConfig(tsconfigPath, options?): object;
271
271
  ```
272
272
 
273
- Defined in: [packages/tsconfig/src/read-tsconfig.ts:460](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/read-tsconfig.ts#L460)
273
+ Defined in: [packages/tsconfig/src/read-tsconfig.ts:460](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/read-tsconfig.ts#L460)
274
274
 
275
275
  #### Parameters
276
276
 
@@ -352,7 +352,7 @@ optional watchOptions: WatchOptions;
352
352
 
353
353
  Instructs the TypeScript compiler how to watch files.
354
354
 
355
- ***
355
+ ---
356
356
 
357
357
  ### writeTsConfig()
358
358
 
@@ -360,7 +360,7 @@ Instructs the TypeScript compiler how to watch files.
360
360
  function writeTsConfig(tsConfig, options): Promise<void>;
361
361
  ```
362
362
 
363
- Defined in: [packages/tsconfig/src/write-tsconfig.ts:17](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/write-tsconfig.ts#L17)
363
+ Defined in: [packages/tsconfig/src/write-tsconfig.ts:17](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/write-tsconfig.ts#L17)
364
364
 
365
365
  An asynchronous function that writes the provided TypeScript configuration object to a tsconfig.json file.
366
366
 
@@ -386,7 +386,7 @@ intersection type of `WriteOptions` and a Record type with an optional `cwd` key
386
386
  A `Promise` that resolves when the tsconfig.json file has been written.
387
387
  The return type of function is `Promise<void>`.
388
388
 
389
- ***
389
+ ---
390
390
 
391
391
  ### writeTsConfigSync()
392
392
 
@@ -394,7 +394,7 @@ The return type of function is `Promise<void>`.
394
394
  function writeTsConfigSync(tsConfig, options): void;
395
395
  ```
396
396
 
397
- Defined in: [packages/tsconfig/src/write-tsconfig.ts:35](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/write-tsconfig.ts#L35)
397
+ Defined in: [packages/tsconfig/src/write-tsconfig.ts:35](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/write-tsconfig.ts#L35)
398
398
 
399
399
  A function that writes the provided TypeScript configuration object to a tsconfig.json file.
400
400
 
@@ -420,7 +420,7 @@ intersection type of `WriteOptions` and a Record type with an optional `cwd` key
420
420
  A `Promise` that resolves when the tsconfig.json file has been written.
421
421
  The return type of function is `Promise<void>`.
422
422
 
423
- ***
423
+ ---
424
424
 
425
425
  ### implicitBaseUrlSymbol
426
426
 
@@ -428,9 +428,9 @@ The return type of function is `Promise<void>`.
428
428
  const implicitBaseUrlSymbol: typeof implicitBaseUrlSymbol;
429
429
  ```
430
430
 
431
- Defined in: [packages/tsconfig/src/read-tsconfig.ts:457](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/read-tsconfig.ts#L457)
431
+ Defined in: [packages/tsconfig/src/read-tsconfig.ts:457](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/read-tsconfig.ts#L457)
432
432
 
433
- ***
433
+ ---
434
434
 
435
435
  ### FindTsConfigOptions
436
436
 
@@ -438,14 +438,14 @@ Defined in: [packages/tsconfig/src/read-tsconfig.ts:457](https://github.com/visu
438
438
  type FindTsConfigOptions = ReadTsConfigOptions & object;
439
439
  ```
440
440
 
441
- Defined in: [packages/tsconfig/src/find-tsconfig.ts:10](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/find-tsconfig.ts#L10)
441
+ Defined in: [packages/tsconfig/src/find-tsconfig.ts:10](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/find-tsconfig.ts#L10)
442
442
 
443
443
  #### Type declaration
444
444
 
445
445
  ##### cache?
446
446
 
447
447
  ```ts
448
- optional cache:
448
+ optional cache:
449
449
  | Map<string, TsConfigJsonResolved>
450
450
  | boolean;
451
451
  ```
@@ -456,7 +456,7 @@ optional cache:
456
456
  optional configFileName: string;
457
457
  ```
458
458
 
459
- ***
459
+ ---
460
460
 
461
461
  ### ReadTsConfigOptions
462
462
 
@@ -464,7 +464,7 @@ optional configFileName: string;
464
464
  type ReadTsConfigOptions = object;
465
465
  ```
466
466
 
467
- Defined in: [packages/tsconfig/src/read-tsconfig.ts:444](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/read-tsconfig.ts#L444)
467
+ Defined in: [packages/tsconfig/src/read-tsconfig.ts:444](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/read-tsconfig.ts#L444)
468
468
 
469
469
  #### Properties
470
470
 
@@ -474,7 +474,7 @@ Defined in: [packages/tsconfig/src/read-tsconfig.ts:444](https://github.com/visu
474
474
  optional tscCompatible: "5.3" | "5.4" | "5.5" | "5.6" | true;
475
475
  ```
476
476
 
477
- Defined in: [packages/tsconfig/src/read-tsconfig.ts:452](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/read-tsconfig.ts#L452)
477
+ Defined in: [packages/tsconfig/src/read-tsconfig.ts:452](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/read-tsconfig.ts#L452)
478
478
 
479
479
  Make the configuration compatible with the specified TypeScript version.
480
480
 
@@ -483,10 +483,10 @@ When `true`, it will make the configuration compatible with the latest TypeScrip
483
483
  ###### Default
484
484
 
485
485
  ```ts
486
- undefined
486
+ undefined;
487
487
  ```
488
488
 
489
- ***
489
+ ---
490
490
 
491
491
  ### TsConfigJsonResolved
492
492
 
@@ -494,9 +494,9 @@ undefined
494
494
  type TsConfigJsonResolved = Except<TsConfigJson, "extends">;
495
495
  ```
496
496
 
497
- Defined in: [packages/tsconfig/src/types.ts:3](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/types.ts#L3)
497
+ Defined in: [packages/tsconfig/src/types.ts:3](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/types.ts#L3)
498
498
 
499
- ***
499
+ ---
500
500
 
501
501
  ### TsConfigResult
502
502
 
@@ -504,7 +504,7 @@ Defined in: [packages/tsconfig/src/types.ts:3](https://github.com/visulima/visul
504
504
  type TsConfigResult = object;
505
505
  ```
506
506
 
507
- Defined in: [packages/tsconfig/src/find-tsconfig.ts:15](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/find-tsconfig.ts#L15)
507
+ Defined in: [packages/tsconfig/src/find-tsconfig.ts:15](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/find-tsconfig.ts#L15)
508
508
 
509
509
  #### Properties
510
510
 
@@ -514,7 +514,7 @@ Defined in: [packages/tsconfig/src/find-tsconfig.ts:15](https://github.com/visul
514
514
  config: TsConfigJsonResolved;
515
515
  ```
516
516
 
517
- Defined in: [packages/tsconfig/src/find-tsconfig.ts:16](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/find-tsconfig.ts#L16)
517
+ Defined in: [packages/tsconfig/src/find-tsconfig.ts:16](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/find-tsconfig.ts#L16)
518
518
 
519
519
  ##### path
520
520
 
@@ -522,7 +522,7 @@ Defined in: [packages/tsconfig/src/find-tsconfig.ts:16](https://github.com/visul
522
522
  path: string;
523
523
  ```
524
524
 
525
- Defined in: [packages/tsconfig/src/find-tsconfig.ts:17](https://github.com/visulima/visulima/blob/661c80ea1e97b45df0793299e0ce381014eae5c0/packages/tsconfig/src/find-tsconfig.ts#L17)
525
+ Defined in: [packages/tsconfig/src/find-tsconfig.ts:17](https://github.com/visulima/visulima/blob/afe199ce97ec3025aa13484407254660803d8d9c/packages/tsconfig/src/find-tsconfig.ts#L17)
526
526
 
527
527
  <!-- /TYPEDOC -->
528
528
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("./packem_shared/findTsConfig-BBvqkZJ6.cjs"),e=require("./packem_shared/implicitBaseUrlSymbol-DMcyudm3.cjs"),n=require("./packem_shared/writeTsConfig-C99ubsh6.cjs");exports.findTsConfig=i.findTsConfig;exports.findTsConfigSync=i.findTsConfigSync;exports.implicitBaseUrlSymbol=e.implicitBaseUrlSymbol;exports.readTsConfig=e.readTsConfig;exports.writeTsConfig=n.writeTsConfig;exports.writeTsConfigSync=n.writeTsConfigSync;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("./packem_shared/findTsConfig-B1SNRXnt.cjs"),e=require("./packem_shared/implicitBaseUrlSymbol-B_X9pk9Z.cjs"),n=require("./packem_shared/writeTsConfig-C99ubsh6.cjs");exports.findTsConfig=i.findTsConfig;exports.findTsConfigSync=i.findTsConfigSync;exports.implicitBaseUrlSymbol=e.implicitBaseUrlSymbol;exports.readTsConfig=e.readTsConfig;exports.writeTsConfig=n.writeTsConfig;exports.writeTsConfigSync=n.writeTsConfigSync;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,83 @@
1
1
  import { WriteJsonOptions } from '@visulima/fs';
2
2
 
3
- declare global {
4
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
5
- interface SymbolConstructor {
6
- readonly observable: symbol;
7
- }
3
+ /**
4
+ Returns a boolean for whether the given type is `any`.
5
+
6
+ @link https://stackoverflow.com/a/49928360/1490091
7
+
8
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
9
+
10
+ @example
11
+ ```
12
+ import type {IsAny} from 'type-fest';
13
+
14
+ const typedObject = {a: 1, b: 2} as const;
15
+ const anyObject: any = {a: 1, b: 2};
16
+
17
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
18
+ return obj[key];
19
+ }
20
+
21
+ const typedA = get(typedObject, 'a');
22
+ //=> 1
23
+
24
+ const anyA = get(anyObject, 'a');
25
+ //=> any
26
+ ```
27
+
28
+ @category Type Guard
29
+ @category Utilities
30
+ */
31
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
32
+
33
+ /**
34
+ Returns a boolean for whether the given key is an optional key of type.
35
+
36
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
37
+
38
+ @example
39
+ ```
40
+ import type {IsOptionalKeyOf} from 'type-fest';
41
+
42
+ interface User {
43
+ name: string;
44
+ surname: string;
45
+
46
+ luckyNumber?: number;
47
+ }
48
+
49
+ interface Admin {
50
+ name: string;
51
+ surname?: string;
8
52
  }
9
53
 
54
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
55
+ //=> true
56
+
57
+ type T2 = IsOptionalKeyOf<User, 'name'>;
58
+ //=> false
59
+
60
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
61
+ //=> boolean
62
+
63
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
64
+ //=> false
65
+
66
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
67
+ //=> boolean
68
+ ```
69
+
70
+ @category Type Guard
71
+ @category Utilities
72
+ */
73
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
74
+ IsAny<Type | Key> extends true ? never
75
+ : Key extends keyof Type
76
+ ? Type extends Record<Key, Type[Key]>
77
+ ? false
78
+ : true
79
+ : false;
80
+
10
81
  /**
11
82
  Extract all optional keys from the given type.
12
83
 
@@ -40,11 +111,14 @@ const update2: UpdateOperation<User> = {
40
111
 
41
112
  @category Utilities
42
113
  */
43
- type OptionalKeysOf<BaseType extends object> =
44
- BaseType extends unknown // For distributing `BaseType`
45
- ? (keyof {
46
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
47
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
114
+ type OptionalKeysOf<Type extends object> =
115
+ Type extends unknown // For distributing `Type`
116
+ ? (keyof {[Key in keyof Type as
117
+ IsOptionalKeyOf<Type, Key> extends false
118
+ ? never
119
+ : Key
120
+ ]: never
121
+ }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
48
122
  : never; // Should never happen
49
123
 
50
124
  /**
@@ -71,9 +145,9 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
71
145
 
72
146
  @category Utilities
73
147
  */
74
- type RequiredKeysOf<BaseType extends object> =
75
- BaseType extends unknown // For distributing `BaseType`
76
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
148
+ type RequiredKeysOf<Type extends object> =
149
+ Type extends unknown // For distributing `Type`
150
+ ? Exclude<keyof Type, OptionalKeysOf<Type>>
77
151
  : never; // Should never happen
78
152
 
79
153
  /**
@@ -120,61 +194,68 @@ endIfEqual('abc', '123');
120
194
  type IsNever<T> = [T] extends [never] ? true : false;
121
195
 
122
196
  /**
123
- An if-else-like type that resolves depending on whether the given type is `never`.
197
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
124
198
 
125
- @see {@link IsNever}
199
+ Use-cases:
200
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
201
+
202
+ Note:
203
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
204
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
126
205
 
127
206
  @example
128
207
  ```
129
- import type {IfNever} from 'type-fest';
208
+ import {If} from 'type-fest';
130
209
 
131
- type ShouldBeTrue = IfNever<never>;
132
- //=> true
210
+ type A = If<true, 'yes', 'no'>;
211
+ //=> 'yes'
133
212
 
134
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
135
- //=> 'bar'
136
- ```
213
+ type B = If<false, 'yes', 'no'>;
214
+ //=> 'no'
137
215
 
138
- @category Type Guard
139
- @category Utilities
140
- */
141
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
142
- IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
143
- );
216
+ type C = If<boolean, 'yes', 'no'>;
217
+ //=> 'yes' | 'no'
144
218
 
145
- // Can eventually be replaced with the built-in once this library supports
146
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
147
- type NoInfer<T> = T extends infer U ? U : never;
219
+ type D = If<any, 'yes', 'no'>;
220
+ //=> 'yes' | 'no'
148
221
 
149
- /**
150
- Returns a boolean for whether the given type is `any`.
222
+ type E = If<never, 'yes', 'no'>;
223
+ //=> 'no'
224
+ ```
151
225
 
152
- @link https://stackoverflow.com/a/49928360/1490091
226
+ @example
227
+ ```
228
+ import {If, IsAny, IsNever} from 'type-fest';
153
229
 
154
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
230
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
231
+ //=> 'not any'
155
232
 
156
- @example
233
+ type B = If<IsNever<never>, 'is never', 'not never'>;
234
+ //=> 'is never'
157
235
  ```
158
- import type {IsAny} from 'type-fest';
159
236
 
160
- const typedObject = {a: 1, b: 2} as const;
161
- const anyObject: any = {a: 1, b: 2};
237
+ @example
238
+ ```
239
+ import {If, IsEqual} from 'type-fest';
162
240
 
163
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
164
- return obj[key];
165
- }
241
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
166
242
 
167
- const typedA = get(typedObject, 'a');
168
- //=> 1
243
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
244
+ //=> 'equal'
169
245
 
170
- const anyA = get(anyObject, 'a');
171
- //=> any
246
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
247
+ //=> 'not equal'
172
248
  ```
173
249
 
174
250
  @category Type Guard
175
251
  @category Utilities
176
252
  */
177
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
253
+ type If<Type extends boolean, IfBranch, ElseBranch> =
254
+ IsNever<Type> extends true
255
+ ? ElseBranch
256
+ : Type extends true
257
+ ? IfBranch
258
+ : ElseBranch;
178
259
 
179
260
  /**
180
261
  Returns a boolean for whether the two given types are equal.
@@ -455,33 +536,10 @@ export type FooBar = Merge<Foo, Bar>;
455
536
  */
456
537
  type Merge<Destination, Source> =
457
538
  Simplify<
458
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
459
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
539
+ SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
540
+ & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
460
541
  >;
461
542
 
462
- /**
463
- An if-else-like type that resolves depending on whether the given type is `any`.
464
-
465
- @see {@link IsAny}
466
-
467
- @example
468
- ```
469
- import type {IfAny} from 'type-fest';
470
-
471
- type ShouldBeTrue = IfAny<any>;
472
- //=> true
473
-
474
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
475
- //=> 'bar'
476
- ```
477
-
478
- @category Type Guard
479
- @category Utilities
480
- */
481
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
482
- IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
483
- );
484
-
485
543
  /**
486
544
  Merges user specified options with default options.
487
545
 
@@ -539,18 +597,13 @@ type ApplyDefaultOptions<
539
597
  Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
540
598
  SpecifiedOptions extends Options,
541
599
  > =
542
- IfAny<SpecifiedOptions, Defaults,
543
- IfNever<SpecifiedOptions, Defaults,
544
- Simplify<Merge<Defaults, {
545
- [Key in keyof SpecifiedOptions
546
- as Key extends OptionalKeysOf<Options>
547
- ? Extract<SpecifiedOptions[Key], undefined> extends never
548
- ? Key
549
- : never
550
- : Key
551
- ]: SpecifiedOptions[Key]
552
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
553
- >>;
600
+ If<IsAny<SpecifiedOptions>, Defaults,
601
+ If<IsNever<SpecifiedOptions>, Defaults,
602
+ Simplify<Merge<Defaults, {
603
+ [Key in keyof SpecifiedOptions
604
+ as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
605
+ ]: SpecifiedOptions[Key]
606
+ }> & Required<Options>>>>;
554
607
 
555
608
  /**
556
609
  Filter out keys from an object.
@@ -679,6 +732,7 @@ declare namespace TsConfigJson {
679
732
  | 'ESNext'
680
733
  | 'Node16'
681
734
  | 'Node18'
735
+ | 'Node20'
682
736
  | 'NodeNext'
683
737
  | 'Preserve'
684
738
  | 'None'
@@ -694,6 +748,7 @@ declare namespace TsConfigJson {
694
748
  | 'esnext'
695
749
  | 'node16'
696
750
  | 'node18'
751
+ | 'node20'
697
752
  | 'nodenext'
698
753
  | 'preserve'
699
754
  | 'none';
@@ -736,7 +791,6 @@ declare namespace TsConfigJson {
736
791
  | 'es2024'
737
792
  | 'esnext';
738
793
 
739
- // eslint-disable-next-line unicorn/prevent-abbreviations
740
794
  export type Lib =
741
795
  | 'ES5'
742
796
  | 'ES6'