bcherny/json-schema-to-typescript

properties + anyOf generates incorrect output

gborobio73 opened this issue · 0 comments

Given this schema:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": "string"
    },
    "validFrom": {
      "type": "string"
    },
    "validTo": {
      "type": "string"
    }
  },
  "anyOf": [
    {
      "required": ["id", "validFrom"]
    },
    {
      "required": ["id", "validTo"]
    }
  ],
  "title": "Assortment"
}

This is the type generated:

export type Assortment = Assortment1 & Assortment2;
export type Assortment1 = {
  [k: string]: unknown;
};

export interface Assortment2 {
  id?: string;
  validFrom?: string;
  validTo?: string;
}

And I was hoping it would generate something like this:

export type Assortment =
  | {
      id: string;
      validFrom: string;
      validTo?: string;
    }
  | {
      id: string;
      validFrom?: string;
      validTo: string;
    };

I might be doing something wrong, so my apologies in advance.

Thank you so much!