glideapps / glideapps/quicktype
Union type not supported for objects
- Dominant language
- TypeScript
- Stars
- 13.9k
- Forks
- 1.2k
- Avg merge
- 8h 53m
- Merged PRs (30d)
- 369
Description
Quicktype version: 15.0.197
We have the following JSON schema (`AssetIdEither.json`):
```json
{
"oneOf": [
{
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"description": "A JavaScript-friendly internal ID for the object.",
"type": "integer",
"minimum": 1,
"maximum": 9007199254740991,
"format": "int64"
}
}
},
{
"type": "object",
"required": [
"externalId"
],
"properties": {
"externalId": {
"description": "The external ID provided by the client. Must be unique within the project.",
"type": "string",
"maxLength": 255
}
}
}
]
}
```
We run this command:
`quicktype --lang ts --out AssetIdEither.ts --src-lang schema --src AssetIdEither.json --just-types`
which then results in (`AssetIdEither.ts`)
```ts
export interface AssetIDEither {
/**
* A JavaScript-friendly internal ID for the object.
*/
id?: number;
/**
* The external ID provided by the client. Must be unique within the project.
*/
externalId?: string;
}
```
But correct output would be:
```ts
export type AssetIDEither =
{
/**
* A JavaScript-friendly internal ID for the object.
*/
id?: number;
} | {
/**
* The external ID provided by the client. Must be unique within the project.
*/
externalId?: string;
};
```
Contributor guide
Assessment
This issue has not been assessed yet.