type-fest 0.4.0 → 0.5.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/index.d.ts +1 -0
- package/package.json +4 -4
- package/readme.md +6 -1
- package/source/basic.d.ts +7 -2
- package/source/literal-union.d.ts +2 -0
- package/source/merge.d.ts +2 -0
- package/source/mutable.d.ts +1 -1
- package/source/package-json.d.ts +1 -1
- package/source/readonly-deep.d.ts +59 -0
package/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export {Mutable} from './source/mutable';
|
|
|
7
7
|
export {Merge} from './source/merge';
|
|
8
8
|
export {MergeExclusive} from './source/merge-exclusive';
|
|
9
9
|
export {RequireAtLeastOne} from './source/require-at-least-one';
|
|
10
|
+
export {ReadonlyDeep} from './source/readonly-deep';
|
|
10
11
|
export {LiteralUnion} from './source/literal-union';
|
|
11
12
|
|
|
12
13
|
// Miscellaneous
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@sindresorhus/tsconfig": "^0.3.0",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^1.
|
|
36
|
-
"eslint-config-xo-typescript": "^0.
|
|
37
|
-
"tsd": "^0.7.
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^1.8.0",
|
|
36
|
+
"eslint-config-xo-typescript": "^0.11.0",
|
|
37
|
+
"tsd": "^0.7.3",
|
|
38
38
|
"xo": "^0.24.0"
|
|
39
39
|
},
|
|
40
40
|
"xo": {
|
package/readme.md
CHANGED
|
@@ -30,6 +30,8 @@ PR welcome for additional commonly needed types and docs improvements. Read the
|
|
|
30
30
|
$ npm install type-fest
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
*Requires TypeScript >=3.2*
|
|
34
|
+
|
|
33
35
|
|
|
34
36
|
## Usage
|
|
35
37
|
|
|
@@ -67,7 +69,8 @@ Click the type names for complete docs.
|
|
|
67
69
|
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
68
70
|
- [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive properties.
|
|
69
71
|
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given properties.
|
|
70
|
-
- [`
|
|
72
|
+
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of a `object`/`Map`/`Set`/`Array` type.
|
|
73
|
+
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
|
71
74
|
|
|
72
75
|
### Miscellaneous
|
|
73
76
|
|
|
@@ -78,6 +81,8 @@ Click the type names for complete docs.
|
|
|
78
81
|
|
|
79
82
|
*If we decline a type addition, we will make sure to document the better solution here.*
|
|
80
83
|
|
|
84
|
+
- [`Diff` and `Spread`](https://github.com/sindresorhus/type-fest/pull/7) - The PR author didn't provide any real-world use-cases and the PR went stale. If you think this type is useful, provide some real-world use-cases and we might reconsider.
|
|
85
|
+
|
|
81
86
|
|
|
82
87
|
## Tips
|
|
83
88
|
|
package/source/basic.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference lib="esnext"/>
|
|
2
|
+
|
|
1
3
|
// TODO: This can just be `export type Primitive = not object` when the `not` keyword is out.
|
|
2
4
|
/**
|
|
3
5
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
@@ -8,7 +10,8 @@ export type Primitive =
|
|
|
8
10
|
| string
|
|
9
11
|
| number
|
|
10
12
|
| boolean
|
|
11
|
-
| symbol
|
|
13
|
+
| symbol
|
|
14
|
+
| bigint;
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
@@ -27,7 +30,9 @@ export type TypedArray =
|
|
|
27
30
|
| Int32Array
|
|
28
31
|
| Uint32Array
|
|
29
32
|
| Float32Array
|
|
30
|
-
| Float64Array
|
|
33
|
+
| Float64Array
|
|
34
|
+
| BigInt64Array
|
|
35
|
+
| BigUint64Array;
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
38
|
Matches a JSON object.
|
package/source/merge.d.ts
CHANGED
package/source/mutable.d.ts
CHANGED
package/source/package-json.d.ts
CHANGED
|
@@ -202,7 +202,7 @@ declare namespace PackageJson {
|
|
|
202
202
|
postrestart?: string;
|
|
203
203
|
} & {
|
|
204
204
|
[scriptName: string]: string;
|
|
205
|
-
}
|
|
205
|
+
};
|
|
206
206
|
|
|
207
207
|
/**
|
|
208
208
|
Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {Primitive} from './basic';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their properties/elements into immutable structures recursively.
|
|
5
|
+
|
|
6
|
+
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
|
7
|
+
|
|
8
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
// data.json
|
|
13
|
+
{
|
|
14
|
+
"foo": ["bar"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// main.ts
|
|
18
|
+
import {ReadonlyDeep} from 'type-fest';
|
|
19
|
+
import dataJson = require('./data.json');
|
|
20
|
+
|
|
21
|
+
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
|
22
|
+
|
|
23
|
+
export default data;
|
|
24
|
+
|
|
25
|
+
// test.ts
|
|
26
|
+
import data from './main';
|
|
27
|
+
|
|
28
|
+
data.foo.push('bar');
|
|
29
|
+
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
30
|
+
```
|
|
31
|
+
*/
|
|
32
|
+
export type ReadonlyDeep<T> = T extends Primitive | ((...arguments: any[]) => unknown)
|
|
33
|
+
? T
|
|
34
|
+
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
35
|
+
? ReadonlyMapDeep<KeyType, ValueType>
|
|
36
|
+
: T extends ReadonlySet<infer ItemType>
|
|
37
|
+
? ReadonlySetDeep<ItemType>
|
|
38
|
+
: T extends object
|
|
39
|
+
? ReadonlyObjectDeep<T>
|
|
40
|
+
: unknown;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
44
|
+
*/
|
|
45
|
+
interface ReadonlyMapDeep<KeyType, ValueType>
|
|
46
|
+
extends ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>> {}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
50
|
+
*/
|
|
51
|
+
interface ReadonlySetDeep<ItemType>
|
|
52
|
+
extends ReadonlySet<ReadonlyDeep<ItemType>> {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
56
|
+
*/
|
|
57
|
+
type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
58
|
+
readonly [PropertyType in keyof ObjectType]: ReadonlyDeep<ObjectType[PropertyType]>
|
|
59
|
+
};
|