Skip to content

jtd-codegen generates invalid typescript if the empty string is allowed as an enum value #16

@mlc

Description

@mlc

Given the following input JTD:

{
  "properties": {
    "a": {"type":  "string"},
    "b": {"enum":  ["", "x", "y"]}
  }
}

jtd-codegen with the --typescript-out flag generates the following output:

// Code generated by jtd-codegen for TypeScript v0.2.0

export enum SimpleB {
   = "",
  X = "x",
  Y = "y",
}

export interface Simple {
  a: string;
  b: SimpleB;
}

However, the line = "" with nothing before the equals sign is rejected by the typescript compiler as a syntax error.

jtd-codegen should either reject the input if I'm misunderstanding something and this is not valid JTD, or it should emit typescript which does not cause the typescript compiler to complain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions