json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Questionable output when property title is "Symbol"

Open meeq opened this issue 4 years ago • 3 comments

This schema:

{
  // ...
  "type": "object",
  "properties": {
    "displaySymbol": {
      "title": "Symbol",
      "type": "string",
      "nullable": true
    },
    // ...
}

Emits:

export type Symbol = string;
export interface Currency {
  displaySymbol: Symbol;
}

Which is a violation of eslint's ban-types rule:

Don't use Symbol as a type. Use symbol instead

This is happening because Symbol is a reserved word in JavaScript.

To resolve this eslint issue and reduce ambiguity, the generated type name for this property should be something distinct, such as Symbol1

meeq avatar Apr 23 '21 17:04 meeq

Symbol isn't a reserved word; it's a global object.

I think it should just have an annotation to exclude es-lint.

pauldraper avatar May 17 '21 03:05 pauldraper

@meeq, what behavior would you expect?

bcherny avatar Sep 12 '21 21:09 bcherny

You shouldn't name your interface Symbol, since Symbol is a global in JS. You might end up with some sneaky bugs and/or TypeScript issues elsewhere in your code

amh4r avatar Sep 25 '21 17:09 amh4r