Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling for JSON columns / more flexible type override support. #99

Closed
dkokotov opened this issue May 8, 2024 · 1 comment

Comments

@dkokotov
Copy link

dkokotov commented May 8, 2024

Currently, JSON columns are typed as unknown in the generated Typescript types.

Ideally, they would have a more specific types. For example, kysely-codegen types them as JsonValue where JsonValue type is included in the generated typings file and defined like this (which is pretty much equivalent to the JsonValue type from type-fest library:

export type JsonArray = JsonValue[];

export type JsonObject = {
  [K in string]?: JsonValue;
};

export type JsonPrimitive = boolean | number | string | null;

export type JsonValue = JsonArray | JsonObject | JsonPrimitive;

I noticed there were some options for type overrides in the library, unfortunately they only really allow you to override the string that is output for the field's type. There is no way to include extra type definitions (or import them). So while I could do

generator kysely {
  provider = "prisma-kysely"
  output   = "./src/generated"
  fileName = "db-schema.ts"
  jsonTypeOverride = "JsonValue"
}

or I could add

/// @kyselyType(JsonValue)`

above the field, but that would leave JsonValue as an undefined type.

Ideally, either (1) the default typing for JSON columns would be the same as kysely-codegen, or (2) there would be a way to inject additional type definitions / arbitrary typescript into the generated file's preamble (similar to how it creates definitions for Timestamp and some others). Another option would be to do (1) but make it a configurable behavior with an additional configuration parameter.

I can potentially open a PR to do any of the above, but would be curious which of the above approaches would be acceptable / preferable. The simplest, of course, would just be to do (1).

@valtyr
Copy link
Owner

valtyr commented May 21, 2024

Hey there! I really need to add some documentation for this... but it's already possible to reference external types in prisma-kysely. For more info you can check out my comments on this issue:

#83 (comment)

@valtyr valtyr closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants