-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Unable to assign values to fields marked as Generated in TypeScript. #64
Comments
Key @noccio-nocci, here's a passage from the Kysely docs:
Here the key word is optional. Kysely allows the user to optionally provide values for generated fields. There's another type called |
I did a little type helper that removes the It scans the provided type looking for the import { ColumnType } from 'kysely';
export type Clean<T> = { [K in keyof T]-?: T[K] extends ColumnType<infer S> ? S : T[K] };
type User = {
id: Generated<string>
name: string
age: number
};
type CleanedUser = Clean<User>;
/* result - {
id: string;
name: string;
age: number
} */
|
@mateusm09 The move here would probably be to use the Selectable, Insertable, Updateable etc. type helpers from Kysely. The types generated from Check out the examples at the bottom of the code block here: |
Fields with
@default
directives in the Prisma schema are converted to typeGenerated
in the generated type.ts.While this makes sense for fields where the database is responsible for generating the value (like auto-incremented IDs or timestamps), it becomes problematic for fields where I need to assign a value during insert or update operations. TypeScript throws a type error when I try to assign a value to these
Generated
fields.Here's an example of a generated type:
Is there a recommended way to handle this situation? Or would you consider adding an option that would allow us to distinguish between fields that are always generated by the database and fields that can be assigned manually?
The text was updated successfully, but these errors were encountered: