Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properties + anyOf generates incorrect output #567

Open
gborobio73 opened this issue Jan 11, 2024 · 0 comments
Open

properties + anyOf generates incorrect output #567

gborobio73 opened this issue Jan 11, 2024 · 0 comments

Comments

@gborobio73
Copy link

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!

@bcherny bcherny changed the title Conditionally required fields generates a "dictionary" type properties + anyOf generates incorrect output Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants