Skip to content

Commit

Permalink
feat(types): Jsonifiable, JsonifiableArray, JsonifiableObject
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 2, 2022
1 parent 3d562a7 commit d3b4e43
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gpgsign
graphqlrc
hmarr
iife
jsonifiable
keyid
larsgw
lcov
Expand Down
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export type { default as JSONArray } from './json-array'
export type { default as JSONObject } from './json-object'
export type { default as JSONPrimitive } from './json-primitive'
export type { default as JSONValue } from './json-value'
export type { default as Jsonifiable } from './jsonifiable'
export type { default as JsonifiableArray } from './jsonifiable-array'
export type { default as JsonifiableObject } from './jsonifiable-object'
export type { default as KeysOptional } from './keys-optional'
export type { default as KeysRequired } from './keys-required'
export type { default as LiteralUnion } from './literal-union'
Expand Down
15 changes: 15 additions & 0 deletions src/types/jsonifiable-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file Type Definitions - JsonifiableArray
* @module tutils/types/JsonifiableArray
*/

import type Jsonifiable from './jsonifiable'

/**
* Matches an array whose items can be losslessly converted to JSON.
*
* @see [`Jsonifiable`]({@link ./jsonifiable.ts})
*/
type JsonifiableArray = readonly Jsonifiable[]

export type { JsonifiableArray as default }
17 changes: 17 additions & 0 deletions src/types/jsonifiable-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file Type Definitions - JsonifiableObject
* @module tutils/types/JsonifiableObject
*/

import type Jsonifiable from './jsonifiable'

/**
* Matches an object whose items can be losslessly converted to JSON.
*
* @see [`Jsonifiable`]({@link ./jsonifiable.ts})
*/
type JsonifiableObject =
| { [K in string]?: Jsonifiable }
| { toJSON(): Jsonifiable }

export type { JsonifiableObject as default }
17 changes: 17 additions & 0 deletions src/types/jsonifiable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file Type Definitions - Jsonifiable
* @module tutils/types/Jsonifiable
*/

import type JSONPrimitive from './json-primitive'
import type JsonifiableArray from './jsonifiable-array'
import type JsonifiableObject from './jsonifiable-object'

/**
* Matches a value that can be losslessly converted to JSON.
*
* Can be used to type values that are expected to pass `JSON.stringify`.
*/
type Jsonifiable = JsonifiableArray | JsonifiableObject | JSONPrimitive

export type { Jsonifiable as default }

0 comments on commit d3b4e43

Please sign in to comment.