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
Bug description
Currently, the TypeScript typings for a
jsoncolumn returns anobject; however, ajsoncolumn will only return a subset of anobjecttype that can be processed throughJSON.stringifyandJSON.parse.How to reproduce
Create any schema with a
jsontype 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
objectfails that test. I limit API responses to a JSON object (not a JavaScriptobject) to prevents values like Date objects from being returned which can't be encoded. This is common in many API's including for use innext.jswhich expectsgetInitialPropsto return JSON values.This is maybe not 100% a proper JSON value type (I'm unsure about where
undefinedshould be in there) but as a starting point:Prisma information
Any schema with a
jsoncolumn typeEnvironment & setup
2.0.0-beta.4
typescript only