@metamask/utils 3.4.0 → 3.5.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.
- package/dist/misc.d.ts +5 -6
- package/dist/misc.js +3 -3
- package/dist/misc.js.map +1 -1
- package/package.json +2 -2
- package/dist/hex.test-d.d.ts +0 -1
- package/dist/hex.test-d.js +0 -16
- package/dist/hex.test-d.js.map +0 -1
- package/dist/json.test-d.d.ts +0 -1
- package/dist/json.test-d.js +0 -62
- package/dist/json.test-d.js.map +0 -1
package/dist/misc.d.ts
CHANGED
|
@@ -22,10 +22,9 @@ export declare type PartialOrAbsent<Value> = Partial<Value> | null | undefined;
|
|
|
22
22
|
*/
|
|
23
23
|
export declare type NonEmptyArray<Element> = [Element, ...Element[]];
|
|
24
24
|
/**
|
|
25
|
-
* A JavaScript object that is not `null`, a function, or an array.
|
|
26
|
-
* can still be an instance of a class.
|
|
25
|
+
* A JavaScript object that is not `null`, a function, or an array.
|
|
27
26
|
*/
|
|
28
|
-
export declare type RuntimeObject = Record<
|
|
27
|
+
export declare type RuntimeObject = Record<PropertyKey, unknown>;
|
|
29
28
|
/**
|
|
30
29
|
* A {@link NonEmptyArray} type guard.
|
|
31
30
|
*
|
|
@@ -50,14 +49,14 @@ export declare function isNullOrUndefined(value: unknown): value is null | undef
|
|
|
50
49
|
*/
|
|
51
50
|
export declare function isObject(value: unknown): value is RuntimeObject;
|
|
52
51
|
/**
|
|
53
|
-
*
|
|
52
|
+
* A type guard for ensuring an object has a property.
|
|
54
53
|
*
|
|
55
|
-
* @param
|
|
54
|
+
* @param objectToCheck - The object to check.
|
|
56
55
|
* @param name - The property name to check for.
|
|
57
56
|
* @returns Whether the specified object has an own property with the specified
|
|
58
57
|
* name, regardless of whether it is enumerable or not.
|
|
59
58
|
*/
|
|
60
|
-
export declare const hasProperty: (
|
|
59
|
+
export declare const hasProperty: <ObjectToCheck extends Object, Property extends PropertyKey>(objectToCheck: ObjectToCheck, name: Property) => objectToCheck is ObjectToCheck & Record<Property, unknown>;
|
|
61
60
|
export declare type PlainObject = Record<number | string | symbol, unknown>;
|
|
62
61
|
/**
|
|
63
62
|
* Predefined sizes (in Bytes) of specific parts of JSON structure.
|
package/dist/misc.js
CHANGED
|
@@ -43,14 +43,14 @@ exports.isObject = isObject;
|
|
|
43
43
|
// Other utility functions
|
|
44
44
|
//
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* A type guard for ensuring an object has a property.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
48
|
+
* @param objectToCheck - The object to check.
|
|
49
49
|
* @param name - The property name to check for.
|
|
50
50
|
* @returns Whether the specified object has an own property with the specified
|
|
51
51
|
* name, regardless of whether it is enumerable or not.
|
|
52
52
|
*/
|
|
53
|
-
const hasProperty = (
|
|
53
|
+
const hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
|
|
54
54
|
exports.hasProperty = hasProperty;
|
|
55
55
|
/**
|
|
56
56
|
* Predefined sizes (in Bytes) of specific parts of JSON structure.
|
package/dist/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,QAAQ;AACR,EAAE;;;
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,QAAQ;AACR,EAAE;;;AAoCF,EAAE;AACF,cAAc;AACd,EAAE;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,KAAgB;IAEhB,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC;AAJD,0CAIC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/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CAeC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;AACxC,CAAC;AAFD,0BAEC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa;;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACvD,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;YACtB,OAAO,KAAK,GAAG,CAAC,CAAC;SAClB;QACD,OAAO,KAAK,GAAG,CAAC,CAAC;IACnB,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,oDAAoD;IACpD,OAAO,IAAI,GAAG,CAAC,MAAA,KAAK,CAAC,KAAK,CAAC,gCAAwB,CAAC,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC;AACrE,CAAC;AAVD,kDAUC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC;AACjC,CAAC;AAFD,kDAEC","sourcesContent":["//\n// Types\n//\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template ObjectValue - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n ObjectValue extends Record<string, unknown>,\n TargetKey extends keyof ObjectValue,\n> = {\n -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];\n} & {\n [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];\n};\n\n/**\n * Useful for representing some value that _might_ be present and / or complete.\n *\n * @template Value - The value that might be present or complete.\n */\nexport type PartialOrAbsent<Value> = Partial<Value> | null | undefined;\n\n/**\n * Like {@link Array}, but always non-empty.\n *\n * @template Element - The non-empty array member type.\n */\nexport type NonEmptyArray<Element> = [Element, ...Element[]];\n\n/**\n * A JavaScript object that is not `null`, a function, or an array.\n */\nexport type RuntimeObject = Record<PropertyKey, unknown>;\n\n//\n// Type Guards\n//\n\n/**\n * A {@link NonEmptyArray} type guard.\n *\n * @template Element - The non-empty array member type.\n * @param value - The value to check.\n * @returns Whether the value is a non-empty array.\n */\nexport function isNonEmptyArray<Element>(\n value: Element[],\n): value is NonEmptyArray<Element> {\n return Array.isArray(value) && value.length > 0;\n}\n\n/**\n * Type guard for \"nullishness\".\n *\n * @param value - Any value.\n * @returns `true` if the value is null or undefined, `false` otherwise.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * A type guard for {@link RuntimeObject}.\n *\n * @param value - The value to check.\n * @returns Whether the specified value has a runtime type of `object` and is\n * neither `null` nor an `Array`.\n */\nexport function isObject(value: unknown): value is RuntimeObject {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n//\n// Other utility functions\n//\n\n/**\n * A type guard for ensuring an object has a property.\n *\n * @param objectToCheck - The object to check.\n * @param name - The property name to check for.\n * @returns Whether the specified object has an own property with the specified\n * name, regardless of whether it is enumerable or not.\n */\nexport const hasProperty = <\n // eslint-disable-next-line @typescript-eslint/ban-types\n ObjectToCheck extends Object,\n Property extends PropertyKey,\n>(\n objectToCheck: ObjectToCheck,\n name: Property,\n): objectToCheck is ObjectToCheck & Record<Property, unknown> =>\n Object.hasOwnProperty.call(objectToCheck, name);\n\nexport type PlainObject = Record<number | string | symbol, unknown>;\n\n/**\n * Predefined sizes (in Bytes) of specific parts of JSON structure.\n */\nexport enum JsonSize {\n Null = 4,\n Comma = 1,\n Wrapper = 1,\n True = 4,\n False = 5,\n Quote = 1,\n Colon = 1,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Date = 24,\n}\n\n/**\n * Regular expression with pattern matching for (special) escaped characters.\n */\nexport const ESCAPE_CHARACTERS_REGEXP = /\"|\\\\|\\n|\\r|\\t/gu;\n\n/**\n * Check if the value is plain object.\n *\n * @param value - Value to be checked.\n * @returns True if an object is the plain JavaScript object,\n * false if the object is not plain (e.g. function).\n */\nexport function isPlainObject(value: unknown): value is PlainObject {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n try {\n let proto = value;\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(value) === proto;\n } catch (_) {\n return false;\n }\n}\n\n/**\n * Check if character is ASCII.\n *\n * @param character - Character.\n * @returns True if a character code is ASCII, false if not.\n */\nexport function isASCII(character: string) {\n return character.charCodeAt(0) <= 127;\n}\n\n/**\n * Calculate string size.\n *\n * @param value - String value to calculate size.\n * @returns Number of bytes used to store whole string value.\n */\nexport function calculateStringSize(value: string): number {\n const size = value.split('').reduce((total, character) => {\n if (isASCII(character)) {\n return total + 1;\n }\n return total + 2;\n }, 0);\n\n // Also detect characters that need backslash escape\n return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;\n}\n\n/**\n * Calculate size of a number ofter JSON serialization.\n *\n * @param value - Number value to calculate size.\n * @returns Number of bytes used to store whole number in JSON.\n */\nexport function calculateNumberSize(value: number): number {\n return value.toString().length;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/debug": "^4.1.7",
|
|
34
34
|
"debug": "^4.3.4",
|
|
35
35
|
"semver": "^7.3.8",
|
|
36
|
-
"superstruct": "^0.
|
|
36
|
+
"superstruct": "^1.0.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@lavamoat/allow-scripts": "^2.0.3",
|
package/dist/hex.test-d.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/hex.test-d.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tsd_1 = require("tsd");
|
|
4
|
-
// Valid hex strings:
|
|
5
|
-
(0, tsd_1.expectAssignable)('0x');
|
|
6
|
-
(0, tsd_1.expectAssignable)('0x0');
|
|
7
|
-
(0, tsd_1.expectAssignable)('0x😀');
|
|
8
|
-
const embeddedString = 'test';
|
|
9
|
-
(0, tsd_1.expectAssignable)(`0x${embeddedString}`);
|
|
10
|
-
// Not valid hex strings:
|
|
11
|
-
(0, tsd_1.expectNotAssignable)(`0X${embeddedString}`);
|
|
12
|
-
(0, tsd_1.expectNotAssignable)(`1x${embeddedString}`);
|
|
13
|
-
(0, tsd_1.expectNotAssignable)(0);
|
|
14
|
-
(0, tsd_1.expectNotAssignable)('0');
|
|
15
|
-
(0, tsd_1.expectNotAssignable)('🙃');
|
|
16
|
-
//# sourceMappingURL=hex.test-d.js.map
|
package/dist/hex.test-d.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.test-d.js","sourceRoot":"","sources":["../src/hex.test-d.ts"],"names":[],"mappings":";;AAAA,6BAA4D;AAI5D,qBAAqB;AAErB,IAAA,sBAAgB,EAAM,IAAI,CAAC,CAAC;AAE5B,IAAA,sBAAgB,EAAM,KAAK,CAAC,CAAC;AAE7B,IAAA,sBAAgB,EAAM,MAAM,CAAC,CAAC;AAE9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,IAAA,sBAAgB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAE7C,yBAAyB;AAEzB,IAAA,yBAAmB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAEhD,IAAA,yBAAmB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAEhD,IAAA,yBAAmB,EAAM,CAAC,CAAC,CAAC;AAE5B,IAAA,yBAAmB,EAAM,GAAG,CAAC,CAAC;AAE9B,IAAA,yBAAmB,EAAM,IAAI,CAAC,CAAC","sourcesContent":["import { expectAssignable, expectNotAssignable } from 'tsd';\n\nimport { Hex } from '.';\n\n// Valid hex strings:\n\nexpectAssignable<Hex>('0x');\n\nexpectAssignable<Hex>('0x0');\n\nexpectAssignable<Hex>('0x😀');\n\nconst embeddedString = 'test';\nexpectAssignable<Hex>(`0x${embeddedString}`);\n\n// Not valid hex strings:\n\nexpectNotAssignable<Hex>(`0X${embeddedString}`);\n\nexpectNotAssignable<Hex>(`1x${embeddedString}`);\n\nexpectNotAssignable<Hex>(0);\n\nexpectNotAssignable<Hex>('0');\n\nexpectNotAssignable<Hex>('🙃');\n"]}
|
package/dist/json.test-d.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/json.test-d.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tsd_1 = require("tsd");
|
|
5
|
-
// Valid Json:
|
|
6
|
-
(0, tsd_1.expectAssignable)(null);
|
|
7
|
-
(0, tsd_1.expectAssignable)(false);
|
|
8
|
-
(0, tsd_1.expectAssignable)('');
|
|
9
|
-
(0, tsd_1.expectAssignable)(0);
|
|
10
|
-
(0, tsd_1.expectAssignable)([]);
|
|
11
|
-
(0, tsd_1.expectAssignable)({});
|
|
12
|
-
(0, tsd_1.expectAssignable)([0]);
|
|
13
|
-
(0, tsd_1.expectAssignable)({ a: 0 });
|
|
14
|
-
(0, tsd_1.expectAssignable)({ deeply: [{ nested: 1 }, 'mixed', 'types', 0] });
|
|
15
|
-
(0, tsd_1.expectAssignable)(['array', { nested: { mixed: true, types: null } }, 0]);
|
|
16
|
-
const jsonCompatibleType = { c: 0 };
|
|
17
|
-
(0, tsd_1.expectAssignable)(jsonCompatibleType);
|
|
18
|
-
// Invalid Json:
|
|
19
|
-
(0, tsd_1.expectNotAssignable)(undefined);
|
|
20
|
-
(0, tsd_1.expectNotAssignable)(new Date());
|
|
21
|
-
(0, tsd_1.expectNotAssignable)(() => 0);
|
|
22
|
-
(0, tsd_1.expectNotAssignable)(new Set());
|
|
23
|
-
(0, tsd_1.expectNotAssignable)(new Map());
|
|
24
|
-
(0, tsd_1.expectNotAssignable)(Symbol('test'));
|
|
25
|
-
(0, tsd_1.expectNotAssignable)({ a: new Date() });
|
|
26
|
-
(0, tsd_1.expectNotAssignable)(5);
|
|
27
|
-
const interfaceWithOptionalProperty = { a: 0 };
|
|
28
|
-
(0, tsd_1.expectNotAssignable)(interfaceWithOptionalProperty);
|
|
29
|
-
const interfaceWithDate = { a: new Date() };
|
|
30
|
-
(0, tsd_1.expectNotAssignable)(interfaceWithDate);
|
|
31
|
-
const interfaceWithOptionalDate = { a: new Date() };
|
|
32
|
-
(0, tsd_1.expectNotAssignable)(interfaceWithOptionalDate);
|
|
33
|
-
const interfaceWithUndefinedTypeUnion = {
|
|
34
|
-
a: 0,
|
|
35
|
-
};
|
|
36
|
-
(0, tsd_1.expectNotAssignable)(interfaceWithUndefinedTypeUnion);
|
|
37
|
-
const interfaceWithFunction = { a: () => 0 };
|
|
38
|
-
(0, tsd_1.expectNotAssignable)(interfaceWithFunction);
|
|
39
|
-
const typeWithDate = { a: new Date() };
|
|
40
|
-
(0, tsd_1.expectNotAssignable)(typeWithDate);
|
|
41
|
-
const typeWithOptionalDate = { a: new Date() };
|
|
42
|
-
(0, tsd_1.expectNotAssignable)(typeWithOptionalDate);
|
|
43
|
-
const typeWithUndefinedTypeUnion = {
|
|
44
|
-
a: 0,
|
|
45
|
-
};
|
|
46
|
-
(0, tsd_1.expectNotAssignable)(typeWithUndefinedTypeUnion);
|
|
47
|
-
const typeWithFunction = { a: () => 0 };
|
|
48
|
-
(0, tsd_1.expectNotAssignable)(typeWithFunction);
|
|
49
|
-
const typeWithOptionalProperty = { a: undefined };
|
|
50
|
-
(0, tsd_1.expectNotAssignable)(typeWithOptionalProperty);
|
|
51
|
-
// Edge cases:
|
|
52
|
-
// The Json type doesn't protect against the `any` type.
|
|
53
|
-
(0, tsd_1.expectAssignable)(null);
|
|
54
|
-
const a = { a: 0 };
|
|
55
|
-
(0, tsd_1.expectNotAssignable)(a);
|
|
56
|
-
// The Json type gets confused by classes. This class instance is valid Json,
|
|
57
|
-
// but it's incompatible with the Json type.
|
|
58
|
-
class Foo {
|
|
59
|
-
}
|
|
60
|
-
const foo = new Foo();
|
|
61
|
-
(0, tsd_1.expectNotAssignable)(foo);
|
|
62
|
-
//# sourceMappingURL=json.test-d.js.map
|
package/dist/json.test-d.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json.test-d.js","sourceRoot":"","sources":["../src/json.test-d.ts"],"names":[],"mappings":";AAAA,mEAAmE;;AAEnE,6BAA4D;AAI5D,cAAc;AAEd,IAAA,sBAAgB,EAAO,IAAI,CAAC,CAAC;AAE7B,IAAA,sBAAgB,EAAO,KAAK,CAAC,CAAC;AAE9B,IAAA,sBAAgB,EAAO,EAAE,CAAC,CAAC;AAE3B,IAAA,sBAAgB,EAAO,CAAC,CAAC,CAAC;AAE1B,IAAA,sBAAgB,EAAO,EAAE,CAAC,CAAC;AAE3B,IAAA,sBAAgB,EAAO,EAAE,CAAC,CAAC;AAE3B,IAAA,sBAAgB,EAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5B,IAAA,sBAAgB,EAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAEjC,IAAA,sBAAgB,EAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAEzE,IAAA,sBAAgB,EAAO,CAAC,OAAO,EAAE,EA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AAE,CAAC,CAAC,EAAE,CAAC;AACpE,IAAA,yBAAmB,EAAO,qBAAqB,CAAC,CAAC;AAKjD,MAAM,YAAY,GAAiB,EAAE,CAAC,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;AACrD,IAAA,yBAAmB,EAAO,YAAY,CAAC,CAAC;AAKxC,MAAM,oBAAoB,GAAyB,EAAE,CAAC,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;AACrE,IAAA,yBAAmB,EAAO,oBAAoB,CAAC,CAAC;AAKhD,MAAM,0BAA0B,GAA+B;IAC7D,CAAC,EAAE,CAAC;CACL,CAAC;AACF,IAAA,yBAAmB,EAAO,0BAA0B,CAAC,CAAC;AAKtD,MAAM,gBAAgB,GAAqB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;AAC1D,IAAA,yBAAmB,EAAO,gBAAgB,CAAC,CAAC;AAK5C,MAAM,wBAAwB,GAA6B,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC;AAC5E,IAAA,yBAAmB,EAAO,wBAAwB,CAAC,CAAC;AAEpD,cAAc;AAEd,wDAAwD;AACxD,IAAA,sBAAgB,EAAO,IAAW,CAAC,CAAC;AAOpC,MAAM,CAAC,GAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACtB,IAAA,yBAAmB,EAAO,CAAC,CAAC,CAAC;AAE7B,6EAA6E;AAC7E,4CAA4C;AAC5C,MAAM,GAAG;CAER;AACD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AACtB,IAAA,yBAAmB,EAAO,GAAG,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions */\n\nimport { expectAssignable, expectNotAssignable } from 'tsd';\n\nimport type { Json } from '.';\n\n// Valid Json:\n\nexpectAssignable<Json>(null);\n\nexpectAssignable<Json>(false);\n\nexpectAssignable<Json>('');\n\nexpectAssignable<Json>(0);\n\nexpectAssignable<Json>([]);\n\nexpectAssignable<Json>({});\n\nexpectAssignable<Json>([0]);\n\nexpectAssignable<Json>({ a: 0 });\n\nexpectAssignable<Json>({ deeply: [{ nested: 1 }, 'mixed', 'types', 0] });\n\nexpectAssignable<Json>(['array', { nested: { mixed: true, types: null } }, 0]);\n\ntype JsonCompatibleType = {\n c: number;\n};\nconst jsonCompatibleType: JsonCompatibleType = { c: 0 };\nexpectAssignable<Json>(jsonCompatibleType);\n\n// Invalid Json:\n\nexpectNotAssignable<Json>(undefined);\n\nexpectNotAssignable<Json>(new Date());\n\nexpectNotAssignable<Json>(() => 0);\n\nexpectNotAssignable<Json>(new Set());\n\nexpectNotAssignable<Json>(new Map());\n\nexpectNotAssignable<Json>(Symbol('test'));\n\nexpectNotAssignable<Json>({ a: new Date() });\n\nexpectNotAssignable<Json>(5 as number | undefined);\n\ninterface InterfaceWithOptionalProperty {\n a?: number;\n}\nconst interfaceWithOptionalProperty: InterfaceWithOptionalProperty = { a: 0 };\nexpectNotAssignable<Json>(interfaceWithOptionalProperty);\n\ninterface InterfaceWithDate {\n a: Date;\n}\nconst interfaceWithDate: InterfaceWithDate = { a: new Date() };\nexpectNotAssignable<Json>(interfaceWithDate);\n\ninterface InterfaceWithOptionalDate {\n a?: Date;\n}\nconst interfaceWithOptionalDate: InterfaceWithOptionalDate = { a: new Date() };\nexpectNotAssignable<Json>(interfaceWithOptionalDate);\n\ninterface InterfaceWithUndefinedTypeUnion {\n a: number | undefined;\n}\nconst interfaceWithUndefinedTypeUnion: InterfaceWithUndefinedTypeUnion = {\n a: 0,\n};\nexpectNotAssignable<Json>(interfaceWithUndefinedTypeUnion);\n\ninterface InterfaceWithFunction {\n a: () => number;\n}\nconst interfaceWithFunction: InterfaceWithFunction = { a: () => 0 };\nexpectNotAssignable<Json>(interfaceWithFunction);\n\ntype TypeWithDate = {\n a: Date;\n};\nconst typeWithDate: TypeWithDate = { a: new Date() };\nexpectNotAssignable<Json>(typeWithDate);\n\ntype TypeWithOptionalDate = {\n a?: Date;\n};\nconst typeWithOptionalDate: TypeWithOptionalDate = { a: new Date() };\nexpectNotAssignable<Json>(typeWithOptionalDate);\n\ntype TypeWithUndefinedTypeUnion = {\n a: number | undefined;\n};\nconst typeWithUndefinedTypeUnion: TypeWithUndefinedTypeUnion = {\n a: 0,\n};\nexpectNotAssignable<Json>(typeWithUndefinedTypeUnion);\n\ntype TypeWithFunction = {\n a: () => number;\n};\nconst typeWithFunction: TypeWithFunction = { a: () => 0 };\nexpectNotAssignable<Json>(typeWithFunction);\n\ntype TypeWithOptionalProperty = {\n a?: number | undefined;\n};\nconst typeWithOptionalProperty: TypeWithOptionalProperty = { a: undefined };\nexpectNotAssignable<Json>(typeWithOptionalProperty);\n\n// Edge cases:\n\n// The Json type doesn't protect against the `any` type.\nexpectAssignable<Json>(null as any);\n\n// The Json type gets confused by interfaces. This interface is valid Json,\n// but it's incompatible with the Json type.\ninterface A {\n a: number;\n}\nconst a: A = { a: 0 };\nexpectNotAssignable<Json>(a);\n\n// The Json type gets confused by classes. This class instance is valid Json,\n// but it's incompatible with the Json type.\nclass Foo {\n a!: number;\n}\nconst foo = new Foo();\nexpectNotAssignable<Json>(foo);\n"]}
|