Skip to content

Commit 5a6c896

Browse files
author
A-yon Lee
committed
Add JSONValue and related types in types module
1 parent 7f071c1 commit 5a6c896

8 files changed

Lines changed: 33 additions & 9 deletions

File tree

augment/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare global {
88
}
99

1010
/** This interface represents the abstract constructor/class of the given `T` type. */
11-
export interface AbstractConstructor<T = object> extends Function {
11+
interface AbstractConstructor<T = object> extends Function {
1212
prototype: T;
1313
}
1414

@@ -240,6 +240,18 @@ declare global {
240240
* ```
241241
*/
242242
type Branded<T, B> = T & { [__brand]: B; };
243+
244+
type JSONPrimitive = string | number | boolean | null;
245+
type JSONArray = JSONValue[];
246+
type JSONObject = {
247+
[key: string]: JSONValue | undefined;
248+
};
249+
250+
/**
251+
* The `JSONValue` type represents a value that can be serialized to JSON and
252+
* deserialized from JSON without losing information.
253+
*/
254+
type JSONValue = JSONPrimitive | JSONArray | JSONObject;
243255
}
244256

245257
// @ts-ignore

bundle/jsext.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ayonli/jsext",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"exports": {
55
".": "./index.ts",
66
"./archive": "./archive.ts",

esm/types.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/types.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ayonli/jsext",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "A JavaScript extension package for building strong and modern applications.",
55
"type": "module",
66
"exports": {

types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* The missing utility types for TypeScript.
2+
* The missing builtin classes of JavaScript and utility types for TypeScript.
33
* @module
44
*/
55

@@ -258,3 +258,15 @@ export type MethodDecorator = {
258258
<T>(target: any, prop: string, desc: TypedPropertyDescriptor<T>): void | TypedPropertyDescriptor<T>;
259259
<F extends (...args: any[]) => any>(target: F, context: DecoratorContext): void | F;
260260
};
261+
262+
export type JSONPrimitive = string | number | boolean | null;
263+
export type JSONArray = JSONValue[];
264+
export type JSONObject = {
265+
[key: string]: JSONValue | undefined;
266+
};
267+
268+
/**
269+
* This type represents a value that can be serialized to JSON and deserialized
270+
* from JSON safely without losing information.
271+
*/
272+
export type JSONValue = JSONPrimitive | JSONArray | JSONObject;

0 commit comments

Comments
 (0)