ts-gems 1.1.2 → 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.
@@ -74,7 +74,7 @@ type _DeepPickWritable<T, K extends keyof T = WritableKeys<T>> =
74
74
  * Pick all JSON friendly properties in T deeply
75
75
  */
76
76
  export type DeepPickJson<T> = _DeepPickJson<T>
77
- type _DeepPickJson<T, K extends keyof T = JsonKeys<T>> =
77
+ type _DeepPickJson<T, Keys extends keyof T = JsonKeys<T>> =
78
78
  T extends Builtin ? T
79
79
  : T extends Promise<infer U> ? Promise<DeepPickJson<U>>
80
80
  : T extends Map<infer K, infer V> ? Map<K, DeepPickJson<V>>
@@ -85,4 +85,22 @@ type _DeepPickJson<T, K extends keyof T = JsonKeys<T>> =
85
85
  : T extends WeakSet<infer U> ? WeakSet<DeepPickJson<U>>
86
86
  : IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickJson<T[K]> }
87
87
  : T extends (infer U)[] ? DeepPickJson<U>[]
88
- : { [P in K]: DeepPickJson<Exclude<T[P], undefined>> };
88
+ : { [P in Keys]: DeepPickJson<Exclude<T[P], undefined>> };
89
+
90
+
91
+ /**
92
+ * Pick all JSON friendly properties in T deeply
93
+ */
94
+ export type DeepPickWritableJson<T> = _DeepPickWritableJson<T>
95
+ type _DeepPickWritableJson<T, Keys extends keyof T = Exclude<JsonKeys<T>, ReadonlyKeys<T>>> =
96
+ T extends Builtin ? T
97
+ : T extends Promise<infer U> ? Promise<DeepPickWritableJson<U>>
98
+ : T extends Map<infer K, infer V> ? Map<K, DeepPickWritableJson<V>>
99
+ : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepPickWritableJson<V>>
100
+ : T extends WeakMap<infer K, infer V> ? WeakMap<K, DeepPickWritableJson<V>>
101
+ : T extends Set<infer U> ? Set<DeepPickWritableJson<U>>
102
+ : T extends ReadonlySet<infer U> ? ReadonlySet<DeepPickWritableJson<U>>
103
+ : T extends WeakSet<infer U> ? WeakSet<DeepPickWritableJson<U>>
104
+ : IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickWritableJson<T[K]> }
105
+ : T extends (infer U)[] ? DeepPickWritableJson<U>[]
106
+ : { [P in Keys]: DeepPickWritableJson<Exclude<T[P], undefined>> };
package/lib/keys.ts CHANGED
@@ -51,9 +51,8 @@ export type NonFunctionKeys<T> = Exclude<keyof T, FunctionKeys<T>>;
51
51
  */
52
52
  export type JsonKeys<T> = _JsonKeys<T>;
53
53
  type _JsonKeys<T, J = Required<T>> = ValuesOf<{
54
- [K in keyof J]: IfUndefined<J[K]> extends true
55
- ? never
56
- : K extends symbol
54
+ [K in keyof J]: K extends symbol ? never
55
+ : IfUndefined<J[K]> extends true
57
56
  ? never
58
57
  : IfJson<J[K]> extends true
59
58
  ? K
@@ -71,13 +71,11 @@ export type IfPrimitiveOrAny<T, Y = true, N = false> =
71
71
  export type IfJson<T, Y = true, N = false> =
72
72
  IfNull<T> extends true ? Y :
73
73
  IfNever<T> extends true ? N :
74
- IfUnknown<T> extends true ? N :
75
- IfClass<T> extends true ? N :
76
- IfFunction<T> extends true ? N :
77
- IfUndefined<T> extends true ? N :
78
- T extends symbol ? N :
79
- T extends (infer U)[] ? IfJson<U> extends true ? Y : N
80
- : Y;
74
+ T extends Function ? N :
75
+ T extends symbol ? N :
76
+ IfUndefined<T> extends true ? N :
77
+ T extends (infer U)[] ? IfJson<U> extends true ? Y : N
78
+ : Y;
81
79
 
82
80
  export type IfJsonOrAny<T, Y = true, N = false> =
83
81
  IfAny<T> extends true ? Y : IfJson<T, Y, N>;
package/package.json CHANGED
@@ -12,16 +12,17 @@
12
12
  "lodash",
13
13
  "underscore"
14
14
  ],
15
- "version": "1.1.2",
15
+ "version": "1.2.0",
16
16
  "types": "lib/index.d.ts",
17
17
  "repository": "git@github.com:panates/ts-gems.git",
18
18
  "author": "Eray Hanoglu <e.hanoglu@panates.com>",
19
19
  "license": "MIT",
20
20
  "scripts": {
21
+ "compile": "tsc -b tsconfig.json",
22
+ "lint": "eslint --no-error-on-unmatched-pattern",
21
23
  "test:common": "jest --clearCache && jest --config=./jest.config.js",
22
24
  "test:strict-null": "jest --clearCache && jest --config=./jest.strict-null.config.js",
23
- "test": "npm run test:common && npm run test:strict-null",
24
- "release": "npm run test && npm publish"
25
+ "test": "npm run test:common && npm run test:strict-null"
25
26
  },
26
27
  "files": [
27
28
  "LICENSE",