Using:
- ZibStack.NET.TypeGen 3.2.8
- GeoJSON.Text 1.1.0
Problem:
- There is no way for a dotnet class property to be annotated with a particular type such that a zod schema would enforce that type and use it when inferring the resulting ts type.
Example Code:
public sealed class TypeGenConfig : ITypeGenConfigurator
{
public void Configure(ITypeGenBuilder b)
{
b.Zod(zod =>
{
zod.OutputDir = "generated/zod";
zod.PropertyNameStyle = NameStyle.CamelCase;
zod.EmitInferredTypes = true;
zod.SingleFileName = "schemas.gen.ts";
});
b.ForType<OrderDto>().WithGeneratedTypes(TypeTarget.Zod);
}
}
public sealed class OrderDto
{
public Guid Id { get; init; }
[TsType("Point", ImportFrom = "geojson")]
public Point? DeliveryAreaPoint { get; init; }
[TsType("Feature", ImportFrom = "geojson")]
public Feature? DeliveryAreaFeature { get; init; }
}
Results in:
// @generated by ZibStack.NET.TypeGen — do not edit
import { z } from 'zod';
export const OrderDtoSchema = z.object({
id: z.uuid(),
deliveryAreaPoint: z.unknown().nullish(),
deliveryAreaFeature: z.unknown().nullish(),
});
export type OrderDto = z.infer<typeof OrderDtoSchema>;
The Generated OrderDto.ts file if generating with TypeTarget.TypeScript does work and uses the type appropriately
Using:
Problem:
Example Code:
Results in:
The Generated OrderDto.ts file if generating with TypeTarget.TypeScript does work and uses the type appropriately