type-fest 2.11.2 → 2.12.2
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 +1 -1
- package/readme.md +21 -1
- package/source/get.d.ts +7 -2
- package/source/jsonify.d.ts +8 -1
- package/source/package-json.d.ts +17 -2
- package/source/tsconfig-json.d.ts +75 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -185,7 +185,7 @@ Click the type names for complete docs.
|
|
|
185
185
|
|
|
186
186
|
### Miscellaneous
|
|
187
187
|
|
|
188
|
-
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
|
|
188
|
+
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). It also includes support for [TypeScript Declaration Files](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) and [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/).
|
|
189
189
|
- [`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).
|
|
190
190
|
|
|
191
191
|
## Declined types
|
|
@@ -199,6 +199,7 @@ Click the type names for complete docs.
|
|
|
199
199
|
- [`Nullish`](https://github.com/sindresorhus/type-fest/pull/318) - The type only saves a couple of characters, not everyone knows what "nullish" means, and I'm also trying to [get away from `null`](https://github.com/sindresorhus/meta/discussions/7).
|
|
200
200
|
- [`TitleCase`](https://github.com/sindresorhus/type-fest/pull/303) - It's not solving a common need and is a better fit for a separate package.
|
|
201
201
|
- [`ExtendOr` and `ExtendAnd`](https://github.com/sindresorhus/type-fest/pull/247) - The benefits don't outweigh having to learn what they mean.
|
|
202
|
+
- [`PackageJsonExtras`](https://github.com/sindresorhus/type-fest/issues/371) - There are too many possible configurations that can be put into `package.json`. If you would like to extend `PackageJson` to support an additional configuration in your project, please see the *Extending existing types* section below.
|
|
202
203
|
|
|
203
204
|
## Alternative type names
|
|
204
205
|
|
|
@@ -209,9 +210,28 @@ Click the type names for complete docs.
|
|
|
209
210
|
|
|
210
211
|
## Tips
|
|
211
212
|
|
|
213
|
+
### Extending existing types
|
|
214
|
+
|
|
215
|
+
- [`PackageJson`](source/package-json.d.ts) - There are a lot of tools that place extra configurations inside the `package.json` file. You can extend `PackageJson` to support these additional configurations.
|
|
216
|
+
<details>
|
|
217
|
+
<summary>
|
|
218
|
+
Example
|
|
219
|
+
</summary>
|
|
220
|
+
|
|
221
|
+
[Playground](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBDAnmApnA3gBQIYGMDW2A5igFIDOEAdnNuXAEJ0o4HFmVUC+cAZlBBBwA5ElQBaXinIxhAbgCwAKFCRYCZGnQAZYFRgooPfoJHSANntmKlysWlaESFanAC8jZo-YuaAMgwLKwBhal5gIgB+AC44XX1DADpQqnCiLhsgA)
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import type {PackageJson as BasePackageJson} from 'type-fest';
|
|
225
|
+
import type {Linter} from 'eslint';
|
|
226
|
+
|
|
227
|
+
type PackageJson = BasePackageJson & {eslintConfig?: Linter.Config};
|
|
228
|
+
```
|
|
229
|
+
</details>
|
|
230
|
+
|
|
212
231
|
### Related
|
|
213
232
|
|
|
214
233
|
- [typed-query-selector](https://github.com/g-plane/typed-query-selector) - Enhances `document.querySelector` and `document.querySelectorAll` with a template literal type that matches element types returned from an HTML element query selector.
|
|
234
|
+
- [`Linter.Config`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/eslint/index.d.ts) - Definitions for the [ESLint configuration schema](https://eslint.org/docs/user-guide/configuring/language-options).
|
|
215
235
|
|
|
216
236
|
### Built-in types
|
|
217
237
|
|
package/source/get.d.ts
CHANGED
|
@@ -97,10 +97,15 @@ type WithStringsKeys = keyof WithStrings;
|
|
|
97
97
|
//=> 'foo' | '0'
|
|
98
98
|
```
|
|
99
99
|
*/
|
|
100
|
-
type WithStringKeys<BaseType
|
|
101
|
-
[Key in StringKeyOf<BaseType>]: BaseType
|
|
100
|
+
type WithStringKeys<BaseType> = {
|
|
101
|
+
[Key in StringKeyOf<BaseType>]: UncheckedIndex<BaseType, Key>
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
Perform a `T[U]` operation if `T` supports indexing.
|
|
106
|
+
*/
|
|
107
|
+
type UncheckedIndex<T, U extends string | number> = [T] extends [Record<string | number, any>] ? T[U] : never;
|
|
108
|
+
|
|
104
109
|
/**
|
|
105
110
|
Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
|
|
106
111
|
|
package/source/jsonify.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ import {JsonPrimitive, JsonValue} from './basic';
|
|
|
3
3
|
// Note: The return value has to be `any` and not `unknown` so it can match `void`.
|
|
4
4
|
type NotJsonable = ((...args: any[]) => any) | undefined;
|
|
5
5
|
|
|
6
|
+
// Note: Handles special case where Arrays with `undefined` are transformed to `'null'` by `JSON.stringify()`
|
|
7
|
+
// Only use with array members
|
|
8
|
+
type JsonifyArrayMember<T> =
|
|
9
|
+
T extends undefined ?
|
|
10
|
+
null | Exclude<T, undefined> :
|
|
11
|
+
Jsonify<T>;
|
|
12
|
+
|
|
6
13
|
/**
|
|
7
14
|
Transform a type to one that is assignable to the `JsonValue` type.
|
|
8
15
|
|
|
@@ -64,7 +71,7 @@ type Jsonify<T> =
|
|
|
64
71
|
? T extends JsonPrimitive
|
|
65
72
|
? T // Primitive is acceptable
|
|
66
73
|
: T extends Array<infer U>
|
|
67
|
-
? Array<
|
|
74
|
+
? Array<JsonifyArrayMember<U>> // It's an array: recursive call for its children
|
|
68
75
|
: T extends object
|
|
69
76
|
? T extends {toJSON(): infer J}
|
|
70
77
|
? (() => J) extends (() => JsonValue) // Is J assignable to JsonValue?
|
package/source/package-json.d.ts
CHANGED
|
@@ -227,11 +227,19 @@ declare namespace PackageJson {
|
|
|
227
227
|
Entry points of a module, optionally with conditions and subpath exports.
|
|
228
228
|
*/
|
|
229
229
|
export type Exports =
|
|
230
|
+
| null
|
|
230
231
|
| string
|
|
231
232
|
| string[]
|
|
232
233
|
| {[key in ExportCondition]: Exports}
|
|
233
234
|
| {[key: string]: Exports}; // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
|
|
234
235
|
|
|
236
|
+
/**
|
|
237
|
+
Import map entries of a module, optionally with conditions.
|
|
238
|
+
*/
|
|
239
|
+
export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
|
|
240
|
+
[key: string]: string | {[key in ExportCondition]: Exports};
|
|
241
|
+
};
|
|
242
|
+
|
|
235
243
|
export interface NonStandardEntryPoints {
|
|
236
244
|
/**
|
|
237
245
|
An ECMAScript module ID that is the primary entry point to the program.
|
|
@@ -416,12 +424,19 @@ declare namespace PackageJson {
|
|
|
416
424
|
main?: string;
|
|
417
425
|
|
|
418
426
|
/**
|
|
419
|
-
|
|
427
|
+
Subpath exports to define entry points of the package.
|
|
420
428
|
|
|
421
|
-
[Read more.](https://nodejs.org/api/
|
|
429
|
+
[Read more.](https://nodejs.org/api/packages.html#subpath-exports)
|
|
422
430
|
*/
|
|
423
431
|
exports?: Exports;
|
|
424
432
|
|
|
433
|
+
/**
|
|
434
|
+
Subpath imports to define internal package import maps that only apply to import specifiers from within the package itself.
|
|
435
|
+
|
|
436
|
+
[Read more.](https://nodejs.org/api/packages.html#subpath-imports)
|
|
437
|
+
*/
|
|
438
|
+
imports?: Imports;
|
|
439
|
+
|
|
425
440
|
/**
|
|
426
441
|
The executable files that should be installed into the `PATH`.
|
|
427
442
|
*/
|
|
@@ -598,6 +598,7 @@ declare namespace TsConfigJson {
|
|
|
598
598
|
Watch input files.
|
|
599
599
|
|
|
600
600
|
@default false
|
|
601
|
+
@deprecated Use watchOptions instead.
|
|
601
602
|
*/
|
|
602
603
|
watch?: boolean;
|
|
603
604
|
|
|
@@ -605,6 +606,8 @@ declare namespace TsConfigJson {
|
|
|
605
606
|
Specify the polling strategy to use when the system runs out of or doesn't support native file watchers.
|
|
606
607
|
|
|
607
608
|
Requires TypeScript version 3.8 or later.
|
|
609
|
+
|
|
610
|
+
@deprecated Use watchOptions.fallbackPolling instead.
|
|
608
611
|
*/
|
|
609
612
|
fallbackPolling?: CompilerOptions.FallbackPolling;
|
|
610
613
|
|
|
@@ -614,6 +617,7 @@ declare namespace TsConfigJson {
|
|
|
614
617
|
Requires TypeScript version 3.8 or later.
|
|
615
618
|
|
|
616
619
|
@default 'useFsEvents'
|
|
620
|
+
@deprecated Use watchOptions.watchDirectory instead.
|
|
617
621
|
*/
|
|
618
622
|
watchDirectory?: CompilerOptions.WatchDirectory;
|
|
619
623
|
|
|
@@ -623,6 +627,7 @@ declare namespace TsConfigJson {
|
|
|
623
627
|
Requires TypeScript version 3.8 or later.
|
|
624
628
|
|
|
625
629
|
@default 'useFsEvents'
|
|
630
|
+
@deprecated Use watchOptions.watchFile instead.
|
|
626
631
|
*/
|
|
627
632
|
watchFile?: CompilerOptions.WatchFile;
|
|
628
633
|
|
|
@@ -990,6 +995,71 @@ declare namespace TsConfigJson {
|
|
|
990
995
|
explainFiles?: boolean;
|
|
991
996
|
}
|
|
992
997
|
|
|
998
|
+
namespace WatchOptions {
|
|
999
|
+
export type WatchFileKind =
|
|
1000
|
+
| 'FixedPollingInterval'
|
|
1001
|
+
| 'PriorityPollingInterval'
|
|
1002
|
+
| 'DynamicPriorityPolling'
|
|
1003
|
+
| 'FixedChunkSizePolling'
|
|
1004
|
+
| 'UseFsEvents'
|
|
1005
|
+
| 'UseFsEventsOnParentDirectory';
|
|
1006
|
+
|
|
1007
|
+
export type WatchDirectoryKind =
|
|
1008
|
+
| 'UseFsEvents'
|
|
1009
|
+
| 'FixedPollingInterval'
|
|
1010
|
+
| 'DynamicPriorityPolling'
|
|
1011
|
+
| 'FixedChunkSizePolling';
|
|
1012
|
+
|
|
1013
|
+
export type PollingWatchKind =
|
|
1014
|
+
| 'FixedInterval'
|
|
1015
|
+
| 'PriorityInterval'
|
|
1016
|
+
| 'DynamicPriority'
|
|
1017
|
+
| 'FixedChunkSize';
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
export interface WatchOptions {
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
Specify the strategy for watching individual files.
|
|
1024
|
+
|
|
1025
|
+
Requires TypeScript version 3.8 or later.
|
|
1026
|
+
|
|
1027
|
+
@default 'UseFsEvents'
|
|
1028
|
+
*/
|
|
1029
|
+
watchFile?: WatchOptions.WatchFileKind | Lowercase<WatchOptions.WatchFileKind>;
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
Specify the strategy for watching directories under systems that lack recursive file-watching functionality.
|
|
1033
|
+
|
|
1034
|
+
Requires TypeScript version 3.8 or later.
|
|
1035
|
+
|
|
1036
|
+
@default 'UseFsEvents'
|
|
1037
|
+
*/
|
|
1038
|
+
watchDirectory?: WatchOptions.WatchDirectoryKind | Lowercase<WatchOptions.WatchDirectoryKind>;
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
Specify the polling strategy to use when the system runs out of or doesn't support native file watchers.
|
|
1042
|
+
|
|
1043
|
+
Requires TypeScript version 3.8 or later.
|
|
1044
|
+
*/
|
|
1045
|
+
fallbackPolling?: WatchOptions.PollingWatchKind | Lowercase<WatchOptions.PollingWatchKind>;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
Enable synchronous updates on directory watchers for platforms that don't support recursive watching natively.
|
|
1049
|
+
*/
|
|
1050
|
+
synchronousWatchDirectory?: boolean;
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
Specifies a list of directories to exclude from watch
|
|
1054
|
+
*/
|
|
1055
|
+
excludeDirectories?: string[];
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
Specifies a list of files to exclude from watch
|
|
1059
|
+
*/
|
|
1060
|
+
excludeFiles?: string[];
|
|
1061
|
+
}
|
|
1062
|
+
|
|
993
1063
|
/**
|
|
994
1064
|
Auto type (.d.ts) acquisition options for this project.
|
|
995
1065
|
|
|
@@ -1048,6 +1118,11 @@ export interface TsConfigJson {
|
|
|
1048
1118
|
*/
|
|
1049
1119
|
compilerOptions?: TsConfigJson.CompilerOptions;
|
|
1050
1120
|
|
|
1121
|
+
/**
|
|
1122
|
+
Instructs the TypeScript compiler how to watch files.
|
|
1123
|
+
*/
|
|
1124
|
+
watchOptions?: TsConfigJson.WatchOptions;
|
|
1125
|
+
|
|
1051
1126
|
/**
|
|
1052
1127
|
Auto type (.d.ts) acquisition options for this project.
|
|
1053
1128
|
|