Skip to content

Commit c523f4d

Browse files
committed
Fix and simplify JSON type definition:
+ Recursive types definition are allowed microsoft/TypeScript#33050 + Export the JSON type for reuse to avoid error like semantic error TS2345: Argument of type '(data: StationWorkerData) => void' is not assignable to parameter of type '(data: JSONValue) => JSONValue' Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
1 parent 0656386 commit c523f4d

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type { IPool } from './pools/pool'
1212
export { DynamicThreadPool } from './pools/thread/dynamic'
1313
export { FixedThreadPool } from './pools/thread/fixed'
1414
export type { ThreadWorkerWithMessageChannel } from './pools/thread/fixed'
15+
export type { JSONValue } from './utility-types'
1516
export { AbstractWorker } from './worker/abstract-worker'
1617
export { ClusterWorker } from './worker/cluster-worker'
1718
export { ThreadWorker } from './worker/thread-worker'

src/utility-types.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,16 @@ import type { KillBehavior } from './worker/worker-options'
77
*/
88
export type Draft<T> = { -readonly [P in keyof T]?: T[P] }
99

10-
/**
11-
* Serializable primitive JSON value.
12-
*/
13-
export type JSONPrimitive = number | boolean | string | null
1410
/**
1511
* Serializable JSON value.
1612
*/
17-
// eslint-disable-next-line no-use-before-define
18-
export type JSONValue = JSONPrimitive | JSONArray | JSONObject
19-
/**
20-
* Serializable JSON object.
21-
*/
22-
export type JSONObject = { [k: string]: JSONValue }
23-
/**
24-
* Serializable JSON array.
25-
*/
26-
export type JSONArray = Array<JSONValue>
13+
export type JSONValue =
14+
| string
15+
| number
16+
| boolean
17+
| null
18+
| JSONValue[]
19+
| Record<string, JSONValue>
2720

2821
/**
2922
* Message object that is passed between worker and main worker.

0 commit comments

Comments
 (0)