glideapps / glideapps/quicktype
TypeScript: Keys are not enforced to be Enums
- Dominant language
- TypeScript
- Stars
- 13.9k
- Forks
- 1.2k
- Avg merge
- 8h 53m
- Merged PRs (30d)
- 369
Description
Hi there!
Thank you for your great tool!
Converting a dictonary-like JSON schema to TS types I have found the following issue:
The keys are not enforced as Enum but are only strings:
```
{
"type": "object",
"required": [
"icon",
"languages"
],
"properties": {
"icon": {
"type": "string"
},
"languages": {
"type": "object",
"propertyNames": {
"type": "string",
"enum": ["de", "en"]
},
"additionalProperties": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"description": {
"type": "string"
},
"recommendation": {
"type": "string"
}
}
}
}
},
"additionalProperties": false
}
```
```
export interface MySchema{
icon: string;
languages: { [key: string]: Language }; // here I would expect the key to be of type enum de/en
}
export interface Language {
description?: string;
name: string;
recommendation?: string;
}
```
I would consider this behaviour as a bug.
It get's worse if I put
`"required": ["en"]`
to my language property. Then it generates:
```
export interface MySchema{
icon: string;
languages: Languages;
}
export interface Languages {
en: Language;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.