You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with `JsonStringify` and `JsonParse` utilities
Test cases added:
```text
JsonString
✔ `JsonString<string>` is assignable to `string`
✔ `string` is not assignable to `JsonString<unknown>`
✔ object is not assignable to `JsonString<unknown>`
is covariant over T
✔ `JsonString<"literal">` is assignable to `JsonString<string>`
✔ `JsonString<Record<string, number>>` is assignable to `JsonString<Record<string, number | undefined>>`
✔ `JsonString<Record<string, number | undefined>>` is assignable to `JsonString<Record<string, unknown>>`
✔ `JsonString<bigint>` is assignable to `JsonString<unknown>`
is not contravariant over T
✔ `JsonString<string>` is not assignable to `JsonString<"literal">`
✔ `JsonString<Record<string, number | undefined>>` is not assignable to `JsonString<Record<string, number>>`
✔ `JsonString<unknown>` is not assignable to `JsonString<bigint>`
JsonStringify and JsonParse
expected usage
supports primitive types
✔ `boolean`
...
✔ branded `string`
✔ `JsonString<string>`
✔ `JsonString<{ arrayOfNumbers: number[] }>`
✔ `JsonString<Record<string, number>>`
✔ `JsonString<Record<string, number | undefined>>`
✔ `JsonString<bigint>`
✔ `JsonString<unknown>`
supports literal types
✔ `true`
✔ `false`
✔ `0`
✔ "string"
✔ `null`
✔ object with literals
✔ array of literals
✔ tuple of literals
✔ specific numeric enum value
✔ specific string enum value
✔ specific const heterogenous enum value
✔ specific computed enum value
supports array types
✔ array of `number`s
✔ readonly array of `number`s
✔ readonly array of simple objects
supports object types
✔ empty object
✔ object with `never`
✔ object with `boolean`
...
✔ `string`|`number` indexed record of `string`s
✔ `string`|`number` indexed record of objects
✔ templated record of `numbers`
✔ `string` indexed record of `number`|`string`s with known properties
✔ `string`|`number` indexed record of `strings` with known `number` property (unassignable)
✔ branded-`string` indexed of `boolean`s
...
✔ object with possible type recursion through union
✔ object with optional type recursion
✔ object with deep type recursion
✔ object with alternating type recursion
✔ simple non-null object json (NonNullJsonObjectWith<never>)
✔ simple read-only non-null object json (ReadonlyNonNullJsonObjectWith<never>)
✔ non-const enums
✔ object with `readonly`
✔ object with getter implemented via value
✔ object with setter implemented via value
✔ object with matched getter and setter implemented via value
✔ object with mismatched getter and setter implemented via value
class instance
✔ with public data (just cares about data)
object with optional property
✔ without property
✔ with undefined value
✔ with defined value
opaque Json types
✔ opaque serializable object
✔ opaque deserialized object
✔ opaque serializable and deserialized object
✔ opaque serializable unknown
✔ opaque deserialized unknown
✔ opaque serializable and deserialized unknown
✔ object with opaque serializable unknown
✔ object with opaque deserialized unknown
✔ recursive type with opaque serializable unknown
✔ recursive type with opaque deserialized unknown
✔ recursive type with opaque serializable and deserialized unknown
✔ recursive branded indexed object with OpaqueJsonDeserialized<unknown>
supports union types
✔ simple json (JsonTypeWith<never>)
✔ simple read-only json (ReadonlyJsonTypeWith<never>)
with NOT fully supported object types
✔ object with self reference throws on serialization
known defect expectations
✔ sparse array of supported types
✔ object with sparse array of supported types
getters and setters allowed but do not propagate
✔ object with `readonly` implemented via getter
✔ object with getter
✔ object with setter
✔ object with matched getter and setter
✔ object with mismatched getter and setter
class instance
with `ignore-inaccessible-members`
✔ with private data ignores private data (that propagates)
invalid input usage
assumptions
✔ const enums are never readable
unsupported types cause compiler error
✔ `undefined`
✔ `unknown`
✔ `symbol`
✔ `unique symbol`
✔ `bigint`
✔ function
✔ function with supported properties
✔ object and function
✔ object with function with supported properties
✔ object with object and function
✔ function with class instance with private data
✔ function with class instance with public data
✔ class instance with private data and is function
✔ class instance with public data and is function
✔ `object` (plain object)
✔ `void`
✔ branded `object`
✔ branded object with `string`
unions with unsupported primitive types
✔ `string | symbol`
✔ `bigint | string`
✔ `bigint | symbol`
✔ `number | bigint | symbol`
array
✔ array of `bigint`s
✔ array of `symbol`s
...
object
✔ object with exactly `bigint`
✔ object with optional `bigint`
✔ object with exactly `symbol`
...
✔ `string` indexed record of `unknown`
✔ `Partial<>` `string` indexed record of `unknown`
✔ `Partial<>` `string` indexed record of `numbers`
✔ `Partial<>` templated record of `numbers`
✔ object with recursion and `symbol`
✔ function object with recursion
✔ object and function with recursion
✔ nested function object with recursion
✔ nested object and function with recursion
✔ object with inherited recursion extended with unsupported properties
object with `undefined`
✔ as exact property type
✔ in union property
...
object with required `unknown`
✔ as exact property type
✔ as exact property type adjacent to recursion
✔ as exact property type in recursion
of class instance
✔ with private data
✔ with private method
✔ with private getter
✔ with private setter
✔ with public method
✔ with private data in optional recursion
opaque Json types requiring extra allowed types
✔ opaque serializable object with `bigint`
✔ opaque deserialized object with `bigint`
✔ opaque serializable and deserialized object with `bigint`
✔ opaque serializable object with number array expecting `bigint` support
✔ opaque deserialized object with number array expecting `bigint` support
✔ opaque serializable and deserialized object with number array expecting `bigint` support
common class instances
✔ Map
✔ ReadonlyMap
✔ Set
✔ ReadonlySet
Fluid types
✔ `IFluidHandle`
✔ object with `IFluidHandle`
special cases
✔ explicit `any` generic still limits allowed types
`number` edge cases
supported
✔ MIN_SAFE_INTEGER
✔ MAX_SAFE_INTEGER
✔ MIN_VALUE
✔ MAX_VALUE
resulting in `null`
✔ NaN
✔ +Infinity
✔ -Infinity
JsonDeserialized
positive compilation tests
supported primitive types are preserved
✔ `JsonString<string>`
✔ `JsonString<{ arrayOfNumbers: number[] }>`
✔ `JsonString<Record<string, number>>`
✔ `JsonString<Record<string, number | undefined>>`
✔ JsonString<bigint>
✔ JsonString<unknown>
JsonSerializable
positive compilation tests
supported primitive types
✔ `JsonString<string>`
✔ `JsonString<{ arrayOfNumbers: number[] }>`
✔ `JsonString<Record<string, number>>`
✔ `JsonString<Record<string, number | undefined>>`
✔ JsonString<bigint>
✔ JsonString<unknown>
```
0 commit comments