bcherny/json-schema-to-typescript
Auf GitHub ansehenproperties + anyOf generates incorrect output
Open
#567 geöffnet am 11. Jan. 2024
bughelp wanted
Repository-Metriken
- Stars
- (3.302 Stars)
- PR-Merge-Metriken
- (Keine gemergten PRs in 30 T)
Beschreibung
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!