@fgv/ts-json-base 5.0.0-28 → 5.0.0-29

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.
@@ -168,6 +168,11 @@ export declare function isJsonObject(from: unknown): from is JsonObject;
168
168
  */
169
169
  export declare function isJsonPrimitive(from: unknown): from is JsonPrimitive;
170
170
 
171
+ /**
172
+ * Helper type to detect if T is exactly unknown.
173
+ */
174
+ declare type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false;
175
+
171
176
  /**
172
177
  * Function to transform the name of a some entity, given an original name
173
178
  * and the contents of the entity.
@@ -208,7 +213,7 @@ declare const jsonArray_2: Validator<JsonArray, IJsonValidatorContext>;
208
213
  * @returns A constrained type that is compatible with JSON serialization.
209
214
  * @public
210
215
  */
211
- export declare type JsonCompatible<T> = T extends JsonPrimitive ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
216
+ export declare type JsonCompatible<T> = IsUnknown<T> extends true ? JsonValue : T extends JsonPrimitive ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
212
217
  [K in keyof T]: JsonCompatible<T[K]>;
213
218
  } : ['Error: Non-JSON type'];
214
219
 
@@ -29,13 +29,17 @@ export interface JsonArray extends Array<JsonValue> {
29
29
  * @public
30
30
  */
31
31
  export type JsonValueType = 'primitive' | 'object' | 'array';
32
+ /**
33
+ * Helper type to detect if T is exactly unknown.
34
+ */
35
+ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false;
32
36
  /**
33
37
  * A constrained type that is compatible with JSON serialization.
34
38
  * @param T - The type to be constrained
35
39
  * @returns A constrained type that is compatible with JSON serialization.
36
40
  * @public
37
41
  */
38
- export type JsonCompatible<T> = T extends JsonPrimitive ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
42
+ export type JsonCompatible<T> = IsUnknown<T> extends true ? JsonValue : T extends JsonPrimitive ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
39
43
  [K in keyof T]: JsonCompatible<T[K]>;
40
44
  } : ['Error: Non-JSON type'];
41
45
  /**
@@ -117,4 +121,5 @@ export declare function sanitizeJson(from: unknown): Result<JsonValue>;
117
121
  * @public
118
122
  */
119
123
  export declare function sanitizeJsonObject<T>(from: T): Result<T>;
124
+ export {};
120
125
  //# sourceMappingURL=common.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-json-base",
3
- "version": "5.0.0-28",
3
+ "version": "5.0.0-29",
4
4
  "description": "Typescript types and basic functions for working with json",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-json-base.d.ts",
@@ -39,12 +39,12 @@
39
39
  "@rushstack/eslint-patch": "~1.12.0",
40
40
  "@rushstack/eslint-config": "4.4.0",
41
41
  "eslint-plugin-tsdoc": "~0.4.0",
42
- "@fgv/ts-utils": "5.0.0-28",
43
- "@fgv/ts-utils-jest": "5.0.0-28",
44
- "@fgv/ts-extras": "5.0.0-28"
42
+ "@fgv/ts-utils": "5.0.0-29",
43
+ "@fgv/ts-extras": "5.0.0-29",
44
+ "@fgv/ts-utils-jest": "5.0.0-29"
45
45
  },
46
46
  "peerDependencies": {
47
- "@fgv/ts-utils": "5.0.0-28"
47
+ "@fgv/ts-utils": "5.0.0-29"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "heft test --clean",