Skip to content

Add test case for type = simpleTypes[] #27

Closed
@darcyparker

Description

@darcyparker

When a type can be multiple simple types but not all types, the resulting interface is not correct.

See https://github.com/bcherny/json-schema-to-typescript/blob/master/dist/index.d.ts#L46
and https://spacetelescope.github.io/understanding-json-schema/reference/type.html

I observed this problem with a larger schema and created this simple test case to demonstrate:

export var schema = {
  "title": "Example Schema",
  "description": "My cool schema",
  "type": "object",
  "properties": {
    "value": {
      "type": ["number", "string"]
    },
    "anotherValue": {
      "type": ["null", "string"]
    }
  },
  "required": ["value"]
}

export var types = `/** My cool schema */
export interface ExampleSchema {
  value: number | string;
  anotherValue: null | string;
}`

I haven't had time to investigate a fix.... but could try if someone else isn't able to get to it before me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions