Description and expected behavior
When I'm using the zenstack/zod generator to generate my return types (for orpc) and then comparing them to the Types generated by the $ModelResult optional fields have incompatibilites.
Screenshots
Example schema to reproduce:
type BasicFields {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
metaData Json @default("{}")
}
model Test with BasicFields {
name String
description String?
}
The types generated by zenstack/zod are:
type Test = {
id: string;
createdAt: Date;
updatedAt: Date;
metaData: any;
name: string;
description?: string | null | undefined; //This seems to be the problem
}
but when I'm passing "test" (imported directly form the model.ts which generates:
export type Test = $ModelResult<$Schema, "Test">;
type Test = {
id: string;
createdAt: Date;
updatedAt: Date;
metaData: JsonValue;
name: string;
description: string | null; //This seems to be the problem
}
the compiler complains about an incompatible type on all optional fields because null and undefined are incompatible.
Argument of type '{ id: string; createdAt: Date; updatedAt: Date; metaData: any; name: string; description?: string | null | undefined; }' is not assignable to parameter of type 'FlatModelResult<SchemaType, "Test", undefined, QueryOptions<SchemaType>>'.
Types of property 'description' are incompatible.
Type 'string | null | undefined' is not assignable to type 'string | null'.
Type 'undefined' is not assignable to type 'string | null'.
This is a representation of code that I'm using:
const testSchema = zodFactory.makeModelSchema("Test")
testFunction({} as z.infer<typeof testSchema>) //Calling the function with the return type returned by my orpc contract
function testFunction(test: Test) {}
I have already tried to set the strictNullChecks: false but then suddenly everything else breaks and no type of $ModelResult gets generated.
Environment (please complete the following information):
- ZenStack version: 3.6.4
- Database type: PostgreSQL
- Node.js/Bun version: Bun v1.3.13
- Package manager: bun
Description and expected behavior
When I'm using the
zenstack/zodgenerator to generate my return types (for orpc) and then comparing them to the Types generated by the$ModelResultoptional fields have incompatibilites.Screenshots
Example schema to reproduce:
The types generated by
zenstack/zodare:but when I'm passing "test" (imported directly form the
model.tswhich generates:the compiler complains about an incompatible type on all optional fields because null and undefined are incompatible.
This is a representation of code that I'm using:
I have already tried to set the
strictNullChecks: falsebut then suddenly everything else breaks and no type of$ModelResultgets generated.Environment (please complete the following information):