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
Please consider supporting me for faster fixes, responses and features Sponsor Me
Problem
When optional fields in the prisma schema are null, the prisma client will explicitly return null from the model query methods. By decorating class properties with @IsOptional(), with the type as someField?: string (as opposed to someField?: string | null), we receive typescript errors such as type string | undefined is not assignable to type string | null.
Suggested solution
When a field in the schema has isRequired = false, append " | null" to the type generated for the class. The resulting generated class would then be defined this way:
I am trying to use this generator as a way of creating classes that can be used in NestJS controllers where an OpenAPI schema is generated. I would like to generate as much code as possible, and this generator seems to fit my needs in all ways except in how it handles creating the type definitions for optional fields.
The text was updated successfully, but these errors were encountered:
Please consider supporting me for faster fixes, responses and features Sponsor Me
Problem
When optional fields in the prisma schema are null, the prisma client will explicitly return
null
from the model query methods. By decorating class properties with@IsOptional()
, with the type assomeField?: string
(as opposed tosomeField?: string | null
), we receive typescript errors such astype string | undefined is not assignable to type string | null
.Suggested solution
When a field in the schema has
isRequired = false
, append" | null"
to the type generated for the class. The resulting generated class would then be defined this way:Alternatives
Additional context
I am trying to use this generator as a way of creating classes that can be used in NestJS controllers where an OpenAPI schema is generated. I would like to generate as much code as possible, and this generator seems to fit my needs in all ways except in how it handles creating the type definitions for optional fields.
The text was updated successfully, but these errors were encountered: