type-fest 1.3.0 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "1.3.0",
3
+ "version": "1.4.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
@@ -60,7 +60,7 @@ PR welcome for additional commonly needed types and docs improvements. Read the
60
60
  $ npm install type-fest
61
61
  ```
62
62
 
63
- *Requires TypeScript >=3.4*
63
+ *Requires TypeScript >=3.8*
64
64
 
65
65
  ## Usage
66
66
 
@@ -119,6 +119,7 @@ Click the type names for complete docs.
119
119
  - [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
120
120
  - [`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.
121
121
  - [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
122
+ - [`Includes`](ts41/includes.ts) - Returns a boolean for whether the given array includes the given item.
122
123
  - [`Simplify`](source/simplify.d.ts) - Flatten the type output to improve type hints shown in editors.
123
124
 
124
125
  ### Template literal types
@@ -149,7 +150,7 @@ Click the type names for complete docs.
149
150
  ### Miscellaneous
150
151
 
151
152
  - [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
152
- - [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 3.7).
153
+ - [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 4.4).
153
154
 
154
155
  ## Declined types
155
156
 
@@ -269,6 +269,11 @@ declare namespace PackageJson {
269
269
  */
270
270
  types?: string;
271
271
 
272
+ /**
273
+ Version selection map of TypeScript.
274
+ */
275
+ typesVersions?: Record<string, Record<string, string[]>>;
276
+
272
277
  /**
273
278
  Location of the bundled TypeScript declaration file. Alias of `types`.
274
279
  */
@@ -3,6 +3,8 @@ declare namespace TsConfigJson {
3
3
  export type JSX =
4
4
  | 'preserve'
5
5
  | 'react'
6
+ | 'react-jsx'
7
+ | 'react-jsxdev'
6
8
  | 'react-native';
7
9
 
8
10
  export type Module =
@@ -12,6 +14,7 @@ declare namespace TsConfigJson {
12
14
  | 'UMD'
13
15
  | 'ES6'
14
16
  | 'ES2015'
17
+ | 'ES2020'
15
18
  | 'ESNext'
16
19
  | 'None'
17
20
  // Lowercase alternatives
@@ -21,6 +24,7 @@ declare namespace TsConfigJson {
21
24
  | 'umd'
22
25
  | 'es6'
23
26
  | 'es2015'
27
+ | 'es2020'
24
28
  | 'esnext'
25
29
  | 'none';
26
30
 
@@ -41,6 +45,7 @@ declare namespace TsConfigJson {
41
45
  | 'ES2018'
42
46
  | 'ES2019'
43
47
  | 'ES2020'
48
+ | 'ES2021'
44
49
  | 'ESNext'
45
50
  // Lowercase alternatives
46
51
  | 'es3'
@@ -52,6 +57,7 @@ declare namespace TsConfigJson {
52
57
  | 'es2018'
53
58
  | 'es2019'
54
59
  | 'es2020'
60
+ | 'es2021'
55
61
  | 'esnext';
56
62
 
57
63
  export type Lib =
@@ -77,6 +83,7 @@ declare namespace TsConfigJson {
77
83
  | 'ES2017.String'
78
84
  | 'ES2017.TypedArrays'
79
85
  | 'ES2018'
86
+ | 'ES2018.AsyncGenerator'
80
87
  | 'ES2018.AsyncIterable'
81
88
  | 'ES2018.Intl'
82
89
  | 'ES2018.Promise'
@@ -87,19 +94,31 @@ declare namespace TsConfigJson {
87
94
  | 'ES2019.String'
88
95
  | 'ES2019.Symbol'
89
96
  | 'ES2020'
97
+ | 'ES2020.BigInt'
98
+ | 'ES2020.Promise'
90
99
  | 'ES2020.String'
91
100
  | 'ES2020.Symbol.WellKnown'
101
+ | 'ES2020.SharedMemory'
102
+ | 'ES2020.Intl'
103
+ | 'ES2021'
104
+ | 'ES2021.Promise'
105
+ | 'ES2021.String'
106
+ | 'ES2021.WeakRef'
92
107
  | 'ESNext'
93
108
  | 'ESNext.Array'
94
109
  | 'ESNext.AsyncIterable'
95
110
  | 'ESNext.BigInt'
96
111
  | 'ESNext.Intl'
112
+ | 'ESNext.Promise'
113
+ | 'ESNext.String'
97
114
  | 'ESNext.Symbol'
115
+ | 'ESNext.WeakRef'
98
116
  | 'DOM'
99
117
  | 'DOM.Iterable'
100
118
  | 'ScriptHost'
101
119
  | 'WebWorker'
102
120
  | 'WebWorker.ImportScripts'
121
+ | 'WebWorker.Iterable'
103
122
  // Lowercase alternatives
104
123
  | 'es5'
105
124
  | 'es6'
@@ -123,6 +142,7 @@ declare namespace TsConfigJson {
123
142
  | 'es2017.string'
124
143
  | 'es2017.typedarrays'
125
144
  | 'es2018'
145
+ | 'es2018.asyncgenerator'
126
146
  | 'es2018.asynciterable'
127
147
  | 'es2018.intl'
128
148
  | 'es2018.promise'
@@ -133,19 +153,31 @@ declare namespace TsConfigJson {
133
153
  | 'es2019.string'
134
154
  | 'es2019.symbol'
135
155
  | 'es2020'
156
+ | 'es2020.bigint'
157
+ | 'es2020.promise'
136
158
  | 'es2020.string'
137
159
  | 'es2020.symbol.wellknown'
160
+ | 'es2020.sharedmemory'
161
+ | 'es2020.intl'
162
+ | 'es2021'
163
+ | 'es2021.promise'
164
+ | 'es2021.string'
165
+ | 'es2021.weakref'
138
166
  | 'esnext'
139
167
  | 'esnext.array'
140
168
  | 'esnext.asynciterable'
141
169
  | 'esnext.bigint'
142
170
  | 'esnext.intl'
171
+ | 'esnext.promise'
172
+ | 'esnext.string'
143
173
  | 'esnext.symbol'
174
+ | 'esnext.weakref'
144
175
  | 'dom'
145
176
  | 'dom.iterable'
146
177
  | 'scripthost'
147
178
  | 'webworker'
148
- | 'webworker.importscripts';
179
+ | 'webworker.importscripts'
180
+ | 'webworker.iterable';
149
181
 
150
182
  export interface Plugin {
151
183
  [key: string]: unknown;
@@ -154,6 +186,35 @@ declare namespace TsConfigJson {
154
186
  */
155
187
  name?: string;
156
188
  }
189
+
190
+ export type ImportsNotUsedAsValues =
191
+ | 'remove'
192
+ | 'preserve'
193
+ | 'error';
194
+
195
+ export type FallbackPolling =
196
+ | 'fixedPollingInterval'
197
+ | 'priorityPollingInterval'
198
+ | 'dynamicPriorityPolling'
199
+ | 'fixedInterval'
200
+ | 'priorityInterval'
201
+ | 'dynamicPriority'
202
+ | 'fixedChunkSize';
203
+
204
+ export type WatchDirectory =
205
+ | 'useFsEvents'
206
+ | 'fixedPollingInterval'
207
+ | 'dynamicPriorityPolling'
208
+ | 'fixedChunkSizePolling';
209
+
210
+ export type WatchFile =
211
+ | 'fixedPollingInterval'
212
+ | 'priorityPollingInterval'
213
+ | 'dynamicPriorityPolling'
214
+ | 'useFsEvents'
215
+ | 'useFsEventsOnParentDirectory'
216
+ | 'fixedChunkSizePolling';
217
+
157
218
  }
158
219
 
159
220
  export interface CompilerOptions {
@@ -192,6 +253,24 @@ declare namespace TsConfigJson {
192
253
  */
193
254
  diagnostics?: boolean;
194
255
 
256
+ /**
257
+ Reduce the number of projects loaded automatically by TypeScript.
258
+
259
+ Requires TypeScript version 4.0 or later.
260
+
261
+ @default false
262
+ */
263
+ disableReferencedProjectLoad?: boolean;
264
+
265
+ /**
266
+ Enforces using indexed accessors for keys declared using an indexed type.
267
+
268
+ Requires TypeScript version 4.2 or later.
269
+
270
+ @default false
271
+ */
272
+ noPropertyAccessFromIndexSignature?: boolean;
273
+
195
274
  /**
196
275
  Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
197
276
 
@@ -206,6 +285,15 @@ declare namespace TsConfigJson {
206
285
  */
207
286
  emitDeclarationOnly?: boolean;
208
287
 
288
+ /**
289
+ Differentiate between undefined and not present when type checking.
290
+
291
+ Requires TypeScript version 4.4 or later.
292
+
293
+ @default false
294
+ */
295
+ exactOptionalPropertyTypes?: boolean;
296
+
209
297
  /**
210
298
  Enable incremental compilation.
211
299
 
@@ -237,7 +325,7 @@ declare namespace TsConfigJson {
237
325
  inlineSources?: boolean;
238
326
 
239
327
  /**
240
- Specify JSX code generation: `'preserve'`, `'react'`, or `'react-native'`.
328
+ Specify what JSX code is generated.
241
329
 
242
330
  @default 'preserve'
243
331
  */
@@ -250,6 +338,33 @@ declare namespace TsConfigJson {
250
338
  */
251
339
  reactNamespace?: string;
252
340
 
341
+ /**
342
+ Specify the JSX factory function to use when targeting React JSX emit, e.g. `React.createElement` or `h`.
343
+
344
+ Requires TypeScript version 2.1 or later.
345
+
346
+ @default 'React.createElement'
347
+ */
348
+ jsxFactory?: string;
349
+
350
+ /**
351
+ Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'.
352
+
353
+ Requires TypeScript version 4.0 or later.
354
+
355
+ @default 'React.Fragment'
356
+ */
357
+ jsxFragmentFactory?: string;
358
+
359
+ /**
360
+ Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.
361
+
362
+ Requires TypeScript version 4.1 or later.
363
+
364
+ @default 'react'
365
+ */
366
+ jsxImportSource?: string;
367
+
253
368
  /**
254
369
  Print names of files part of the compilation.
255
370
 
@@ -269,6 +384,13 @@ declare namespace TsConfigJson {
269
384
  */
270
385
  module?: CompilerOptions.Module;
271
386
 
387
+ /**
388
+ Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6).
389
+
390
+ @default ['AMD', 'System', 'ES6'].includes(module) ? 'classic' : 'node'
391
+ */
392
+ moduleResolution?: 'classic' | 'node';
393
+
272
394
  /**
273
395
  Specifies the end of line sequence to be used when emitting files: 'crlf' (Windows) or 'lf' (Unix).
274
396
 
@@ -461,6 +583,15 @@ declare namespace TsConfigJson {
461
583
  */
462
584
  target?: CompilerOptions.Target;
463
585
 
586
+ /**
587
+ Default catch clause variables as `unknown` instead of `any`.
588
+
589
+ Requires TypeScript version 4.4 or later.
590
+
591
+ @default false
592
+ */
593
+ useUnknownInCatchVariables?: boolean;
594
+
464
595
  /**
465
596
  Watch input files.
466
597
 
@@ -468,6 +599,31 @@ declare namespace TsConfigJson {
468
599
  */
469
600
  watch?: boolean;
470
601
 
602
+ /**
603
+ Specify the polling strategy to use when the system runs out of or doesn't support native file watchers.
604
+
605
+ Requires TypeScript version 3.8 or later.
606
+ */
607
+ fallbackPolling?: CompilerOptions.FallbackPolling;
608
+
609
+ /**
610
+ Specify the strategy for watching directories under systems that lack recursive file-watching functionality.
611
+
612
+ Requires TypeScript version 3.8 or later.
613
+
614
+ @default 'useFsEvents'
615
+ */
616
+ watchDirectory?: CompilerOptions.WatchDirectory;
617
+
618
+ /**
619
+ Specify the strategy for watching individual files.
620
+
621
+ Requires TypeScript version 3.8 or later.
622
+
623
+ @default 'useFsEvents'
624
+ */
625
+ watchFile?: CompilerOptions.WatchFile;
626
+
471
627
  /**
472
628
  Enables experimental support for ES7 decorators.
473
629
 
@@ -482,13 +638,6 @@ declare namespace TsConfigJson {
482
638
  */
483
639
  emitDecoratorMetadata?: boolean;
484
640
 
485
- /**
486
- Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6).
487
-
488
- @default ['AMD', 'System', 'ES6'].includes(module) ? 'classic' : 'node'
489
- */
490
- moduleResolution?: 'classic' | 'node';
491
-
492
641
  /**
493
642
  Do not report errors on unused labels.
494
643
 
@@ -503,6 +652,15 @@ declare namespace TsConfigJson {
503
652
  */
504
653
  noImplicitReturns?: boolean;
505
654
 
655
+ /**
656
+ Add `undefined` to a type when accessed using an index.
657
+
658
+ Requires TypeScript version 4.1 or later.
659
+
660
+ @default false
661
+ */
662
+ noUncheckedIndexedAccess?: boolean;
663
+
506
664
  /**
507
665
  Report errors for fallthrough cases in switch statement.
508
666
 
@@ -510,6 +668,13 @@ declare namespace TsConfigJson {
510
668
  */
511
669
  noFallthroughCasesInSwitch?: boolean;
512
670
 
671
+ /**
672
+ Ensure overriding members in derived classes are marked with an override modifier.
673
+
674
+ @default false
675
+ */
676
+ noImplicitOverride?: boolean;
677
+
513
678
  /**
514
679
  Do not report errors on unreachable code.
515
680
 
@@ -524,6 +689,15 @@ declare namespace TsConfigJson {
524
689
  */
525
690
  forceConsistentCasingInFileNames?: boolean;
526
691
 
692
+ /**
693
+ Emit a v8 CPU profile of the compiler run for debugging.
694
+
695
+ Requires TypeScript version 3.7 or later.
696
+
697
+ @default 'profile.cpuprofile'
698
+ */
699
+ generateCpuProfile?: string;
700
+
527
701
  /**
528
702
  Base directory to resolve non-relative module names.
529
703
  */
@@ -646,13 +820,11 @@ declare namespace TsConfigJson {
646
820
  importHelpers?: boolean;
647
821
 
648
822
  /**
649
- Specify the JSX factory function to use when targeting React JSX emit, e.g. `React.createElement` or `h`.
823
+ Specify emit/checking behavior for imports that are only used for types.
650
824
 
651
- Requires TypeScript version 2.1 or later.
652
-
653
- @default 'React.createElement'
825
+ @default 'remove'
654
826
  */
655
- jsxFactory?: string;
827
+ importsNotUsedAsValues?: CompilerOptions.ImportsNotUsedAsValues;
656
828
 
657
829
  /**
658
830
  Parse in strict mode and emit `'use strict'` for each source file.
@@ -766,6 +938,54 @@ declare namespace TsConfigJson {
766
938
  @default false
767
939
  */
768
940
  resolveJsonModule?: boolean;
941
+
942
+ /**
943
+ Have recompiles in '--incremental' and '--watch' assume that changes within a file will only affect files directly depending on it.
944
+
945
+ Requires TypeScript version 3.8 or later.
946
+
947
+ @default false
948
+ */
949
+ assumeChangesOnlyAffectDirectDependencies?: boolean;
950
+
951
+ /**
952
+ Output more detailed compiler performance information after building.
953
+
954
+ @default false
955
+ */
956
+ extendedDiagnostics?: boolean;
957
+
958
+ /**
959
+ Print names of files that are part of the compilation and then stop processing.
960
+
961
+ @default false
962
+ */
963
+ listFilesOnly?: boolean;
964
+
965
+ /**
966
+ Disable preferring source files instead of declaration files when referencing composite projects.
967
+
968
+ @default true if composite, false otherwise
969
+ */
970
+ disableSourceOfProjectReferenceRedirect?: boolean;
971
+
972
+ /**
973
+ Opt a project out of multi-project reference checking when editing.
974
+
975
+ Requires TypeScript version 3.8 or later.
976
+
977
+ @default false
978
+ */
979
+ disableSolutionSearching?: boolean;
980
+
981
+ /**
982
+ Print names of files which TypeScript sees as a part of your project and the reason they are part of the compilation.
983
+
984
+ Requires TypeScript version 4.2 or later.
985
+
986
+ @default false
987
+ */
988
+ explainFiles?: boolean;
769
989
  }
770
990
 
771
991
  /**
package/ts41/get.d.ts CHANGED
@@ -81,6 +81,8 @@ type PropertyOf<BaseType, Key extends string> =
81
81
  ? undefined
82
82
  : Key extends keyof BaseType
83
83
  ? BaseType[Key]
84
+ : BaseType extends [] | [unknown, ...unknown[]]
85
+ ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
84
86
  : BaseType extends {
85
87
  [n: number]: infer Item;
86
88
  length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
@@ -0,0 +1,31 @@
1
+ /**
2
+ Returns a boolean for whether given two 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;
11
+
12
+ /**
13
+ Returns a boolean for whether the given array includes the given item.
14
+
15
+ This can be useful if another type wants to make a decision based on whether the array includes that item.
16
+
17
+ @example
18
+ ```
19
+ import {Includes} from 'type-fest';
20
+
21
+ type hasRed<array extends any[]> = Includes<array, 'red'>;
22
+ ```
23
+
24
+ @category Utilities
25
+ */
26
+ export type Includes<Value extends any[], Item> =
27
+ IsEqual<Value[0], Item> extends true
28
+ ? true
29
+ : Value extends [Value[0], ...infer rest]
30
+ ? Includes<rest, Item>
31
+ : false;
package/ts41/index.d.ts CHANGED
@@ -20,5 +20,6 @@ export {DelimiterCasedProperties} from './delimiter-cased-properties';
20
20
  export {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
21
21
  export {Split} from './split';
22
22
  export {Trim} from './trim';
23
+ export {Includes} from './includes';
23
24
  export {Get} from './get';
24
25
  export {LastArrayElement} from './last-array-element';
@@ -1,14 +1,6 @@
1
1
  import {SplitIncludingDelimiters} from './delimiter-case';
2
2
  import {SnakeCase} from './snake-case';
3
-
4
- /**
5
- Returns a boolean for whether the given array includes the given item.
6
- */
7
- type Includes<Value extends any[], Item> = {
8
- [P in keyof Value & number as Value[P]]: true;
9
- }[Item] extends true
10
- ? true
11
- : false;
3
+ import {Includes} from './includes';
12
4
 
13
5
  /**
14
6
  Returns a boolean for whether the string is screaming snake case.