Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

JSON types should return a JSON object and not a JavaScript object #691

@thesunny

Description

@thesunny

Bug description

Currently, the TypeScript typings for a json column returns an object; however, a json column will only return a subset of an object type that can be processed through JSON.stringify and JSON.parse.

How to reproduce

Create any schema with a json type and view its type.

Expected behavior

The field type should be returned as a JSON object as opposed to a JavaScript object.

Use case: my API type checks that the return values for an API method are valid JSON objects and returning an object fails that test. I limit API responses to a JSON object (not a JavaScript object) to prevents values like Date objects from being returned which can't be encoded. This is common in many API's including for use in next.js which expects getInitialProps to return JSON values.

This is maybe not 100% a proper JSON value type (I'm unsure about where undefined should be in there) but as a starting point:

export type JSONValue =
  | string
  | number
  | boolean
  | null
  | undefined
  | JSONArray
  | JSONObject

export type JSONArray = Array<JSONValue>

export type JSONObject = {
  [key: string]: JSONValue
}

Prisma information

Any schema with a json column type

Environment & setup

2.0.0-beta.4
typescript only

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions