MakeTypes
MakeTypes copied to clipboard
Special characters in field names
Support field names that are not proper JavaScript identifiers.
e.g.: ")hello"
In the non-identifier case, switch to using index [""] notation for accessing properties on JS objects.
I'd add for not only filed names, but also type names
input was:
{
"stores": [ "xxxx"
],
"products": {
"892303": [
{
"sku": "892304",
"upc": []
},
{
"sku": "10137374",
"upc": []
}
],
"PRD4UH16V3K5TO7": [
{
"sku": "4UH16V3K5TO7",
"upc": []
}
]
},
"origin": "browse"
}
Output:
export interface ProductAvailabitlityRequest {
stores?: (string)[] | null;
products: Products;
origin: string;
}
export interface Products {
892303?: (892303EntityOrPRD4UH16V3K5TO7Entity)[] | null;
PRD4UH16V3K5TO7?: (892303EntityOrPRD4UH16V3K5TO7Entity)[] | null;
}
export interface 892303EntityOrPRD4UH16V3K5TO7Entity {
sku: string;
upc?: (null)[] | null;
}
I'd suggest escapting interface name, say _8923... in this case, and for prop name use quotes (")
Good call. I may revisit this issue in a couple of months, once I finish defending my PhD + moving.
I got blocked by this issue recently, I have a potential fix in https://github.com/jvilk/MakeTypes/pull/18
Just had the same issue
Created:
itineraries:created?: string[] | null;
Should be:
['itineraries:created']?: string[] | null;
Proposed fix: https://github.com/jvilk/MakeTypes/pull/26 You can point your package to https://github.com/RobertjanTuit/MakeTypes temporarily to use until is merged
Actually, those are 2 characters I did not have in the list yet added them.