bcherny/json-schema-to-typescript
GitHub で見るproperties + anyOf generates incorrect output
Open
#567 opened on 2024年1月11日
bughelp wanted
Repository metrics
- Stars
- (3,302 stars)
- PR merge metrics
- (30d に merged PR はありません)
説明
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!