glideapps / glideapps/quicktype

Unable to combine defintions when generating TypeScript from multiple files

Open
#1,543 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

I have two schema files in a directory.

```
{
"type" : "object",
"id" : "WebsiteOrder.json",
"title" : "WebsiteOrder",
"properties" : {
"external_order_ref" : {
"type" : "string"
},
"info" : {
"type" : "object",
"$ref" : "OrderCustomer.schema#",
"required" : true
}
}
}
```

and

```
{
"type" : "object",
"id" : "OrderCustomer",
"title" : "OrderCustomer",
"properties" : {
"first_name" : {
"type" : "string"
},
"last_name" : {
"type" : "string"
},
"email" : {
"type" : "string"
},
"phone" : {
"type" : "string"
},
"post_code" : {
"type" : "string"
},
"country" : {
"type" : "string"
},
"newsletter" : {
"type" : "string"
},
"order_number" : {
"type" : "string",
"required" : true
},
"type" : {
"type" : "string"
}
}
}
```

When I run the command to generate TypeScript types for those schema files, I end up with duplicates in my resultant file. The command I'm using is `npx quicktype --src=res --src-lang=schema --just-types --lang=ts --out=src/types.d.ts` and the resultant file resembles

```
export interface OrderCustomer {
country?: string;
email?: string;
first_name?: string;
last_name?: string;
newsletter?: string;
order_number: string;
phone?: string;
post_code?: string;
type?: string;
}

export interface WebsiteOrder {
external_order_ref?: string;
info: Info;
}

export interface Info {
country?: string;
email?: string;
first_name?: string;
last_name?: string;
newsletter?: string;
order_number: string;
phone?: string;
post_code?: string;
type?: string;
}

```

Is there support (or documentation) or how to unify the resultant types? As you can see, there is both a `Info` and a `OrderCustomer` type. any help is appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.