MakeTypes icon indicating copy to clipboard operation
MakeTypes copied to clipboard

Special characters in field names

Open jvilk opened this issue 8 years ago • 6 comments

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.

jvilk avatar May 12 '17 20:05 jvilk

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 (")

Mart-Bogdan avatar Jul 15 '18 17:07 Mart-Bogdan

Good call. I may revisit this issue in a couple of months, once I finish defending my PhD + moving.

jvilk avatar Jul 16 '18 17:07 jvilk

I got blocked by this issue recently, I have a potential fix in https://github.com/jvilk/MakeTypes/pull/18

renatomariscal avatar Mar 04 '20 17:03 renatomariscal

Just had the same issue Created: itineraries:created?: string[] | null; Should be: ['itineraries:created']?: string[] | null;

realJoshByrnes avatar Jun 30 '21 04:06 realJoshByrnes

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

RobertjanTuit avatar Jan 04 '22 02:01 RobertjanTuit

Actually, those are 2 characters I did not have in the list yet added them.

RobertjanTuit avatar Jan 04 '22 02:01 RobertjanTuit