Skip to content

TsType attribute is unused by Zod Emitter #20

Description

@akersj14

Using:

  • ZibStack.NET.TypeGen 3.2.8
  • GeoJSON.Text 1.1.0

Problem:

  1. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions