Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jahredhope/demo-json-schema-extends-typescript
Demononstrate behavior of json-schema-to-typescript when extending schemas
https://github.com/jahredhope/demo-json-schema-extends-typescript
Last synced: 16 days ago
JSON representation
Demononstrate behavior of json-schema-to-typescript when extending schemas
- Host: GitHub
- URL: https://github.com/jahredhope/demo-json-schema-extends-typescript
- Owner: jahredhope
- Created: 2020-07-16T05:20:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-26T09:50:57.000Z (over 2 years ago)
- Last Synced: 2024-10-19T02:00:24.962Z (29 days ago)
- Language: TypeScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Demo json-schema-to-typescript
This repository demonstrates the different behaviours between `allOf` and `extends` in generated types using json-schema-to-typescript.
This repository contains folders with different implementations where multiple child schemas extend a parent schema. In this case the children `Circle` and `Square` both extend `Shape`.
Both of these folders have generated `types.d.ts` files with some differences.
- The use of `extend` creates the more ideal TypeScript definition however it duplicates the shape definition as `Shape` and `Shape1`.
- The use of `allOf` does not duplicate these definitions.When using `allOf` reused references are declared once and reused.
- [Type definition example](./allOf/types.d.ts)
- [Source code](./allOf/square.json)When using `extends` reused references are duplicated.
- [Type definition example](./extends/types.d.ts)
- [Source code](./extends/square.json)### Setup
Install dependencies
```bash
$ yarn
```Build the type definitions
```bash
$ yarn build
```