bcherny/json-schema-to-typescript

Adding anything to empty property makes it `Record<string,any>` instead of `any`

Open

#176 opened on Aug 20, 2018

View on GitHub
 (4 comments) (0 reactions) (0 assignees)TypeScript (449 forks)github user discovery
buggood first issuehelp wanted

Repository metrics

Stars
 (3,302 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://bepis.com/event.schema.json",
  "title": "Event",
  "properties": {
    "data": {}
  },
  "additionalProperties": false,
  "required": ["data"]
}

produces

export interface Event {
  data: any;
}

but

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://bepis.com/event.schema.json",
  "title": "Event",
  "properties": {
    "data": { "description": "" }
  },
  "additionalProperties": false,
  "required": ["data"]
}

immediately produces

export interface Event {
  data: {
    [k: string]: any;
  };
}

Imo, things that don't affect validation should not change the type output?

Contributor guide