@flashist/appframework 0.0.224 → 0.0.225
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,3 +1,58 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
2
|
+
(...arguments_: infer A): unknown;
|
|
3
|
+
(...arguments_: any[]): unknown;
|
|
4
|
+
} ? unknown[] extends A ? false : true : false;
|
|
5
|
+
export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
6
|
+
export type BuiltIns = Primitive | Date | RegExp;
|
|
7
|
+
/**
|
|
8
|
+
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
9
|
+
|
|
10
|
+
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.
|
|
11
|
+
|
|
12
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
13
|
+
|
|
14
|
+
@example
|
|
15
|
+
```
|
|
16
|
+
// data.json
|
|
17
|
+
{
|
|
18
|
+
"foo": ["bar"]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// main.ts
|
|
22
|
+
import type {DeepReadonly} from 'type-fest';
|
|
23
|
+
import dataJson = require('./data.json');
|
|
24
|
+
|
|
25
|
+
const data: DeepReadonly<typeof dataJson> = dataJson;
|
|
26
|
+
|
|
27
|
+
export default data;
|
|
28
|
+
|
|
29
|
+
// test.ts
|
|
30
|
+
import data from './main';
|
|
31
|
+
|
|
32
|
+
data.foo.push('bar');
|
|
33
|
+
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Note that types containing overloaded functions are not made deeply readonly due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
37
|
+
|
|
38
|
+
@category Object
|
|
39
|
+
@category Array
|
|
40
|
+
@category Set
|
|
41
|
+
@category Map
|
|
42
|
+
*/
|
|
43
|
+
export type DeepReadonly<T> = T extends BuiltIns ? T : T extends (...arguments_: any[]) => unknown ? {} extends DeepReadonlyObject<T> ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & DeepReadonlyObject<T> : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>> ? DeepReadonlyMap<KeyType, ValueType> : T extends Readonly<ReadonlySet<infer ItemType>> ? DeepReadonlySet<ItemType> : T extends readonly [] | readonly [...never[]] ? readonly [] : T extends readonly [infer U, ...infer V] ? readonly [DeepReadonly<U>, ...DeepReadonly<V>] : T extends readonly [...infer U, infer V] ? readonly [...DeepReadonly<U>, DeepReadonly<V>] : T extends ReadonlyArray<infer ItemType> ? ReadonlyArray<DeepReadonly<ItemType>> : T extends object ? DeepReadonlyObject<T> : unknown;
|
|
44
|
+
/**
|
|
45
|
+
Same as `DeepReadonly`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `DeepReadonly`.
|
|
46
|
+
*/
|
|
47
|
+
type DeepReadonlyMap<KeyType, ValueType> = {} & Readonly<ReadonlyMap<DeepReadonly<KeyType>, DeepReadonly<ValueType>>>;
|
|
48
|
+
/**
|
|
49
|
+
Same as `DeepReadonly`, but accepts only `ReadonlySet`s as inputs. Internal helper for `DeepReadonly`.
|
|
50
|
+
*/
|
|
51
|
+
type DeepReadonlySet<ItemType> = {} & Readonly<ReadonlySet<DeepReadonly<ItemType>>>;
|
|
52
|
+
/**
|
|
53
|
+
Same as `DeepReadonly`, but accepts only `object`s as inputs. Internal helper for `DeepReadonly`.
|
|
54
|
+
*/
|
|
55
|
+
type DeepReadonlyObject<ObjectType extends object> = {
|
|
56
|
+
readonly [KeyType in keyof ObjectType]: DeepReadonly<ObjectType[KeyType]>;
|
|
57
|
+
};
|
|
58
|
+
export {};
|