8000 [BUG]: It generates empty typescript interfaces · Issue #2793 · glideapps/quicktype · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[BUG]: It generates empty typescript interfaces #2793
Open
@thany

Description

@thany

When targetting typescript interfaces, an empty object in the samples generates an empty interface. An empty interface, as per the linter has a big drawback:

An empty interface declaration allows any non-nullish value, including literals like 0 and "".

  • If that's what you want, disable this lint rule with an inline comment or configure the 'allowInterfaces' rule option.
  • If you want a type meaning "any object", you probably want object instead.
  • If you want a type meaning "any value", you probably want unknown

So it probably needs to be object in such cases. More information

Issue Type

output

Context (Environment, Version, Language)

Input Format: json
Output Language: typescript

CLI, npm, or app.quicktype.io: app.quicktype.io
Version: n/a

Description

It trips the linter. But more importantly, see linter message - an empty interface doesn't restrict a value to an empty object, which is what you might expect, but that's not how it works.

Input Data

{
  "Labels": {
    "AccountNumber": "Accountnumber",
    "Title": "Create new Service Address"
  },
  "Hints": {
  }
}

Expected Behaviour / Output

export interface Welcome {
    readonly Labels: Labels;
    readonly Hints:  object;
}

export interface Labels {
    readonly AccountNumber: string;
    readonly Title:         string;
}

Current Behaviour / Output

export interface Welcome {
    readonly Labels: Labels;
    readonly Hints:  Hints;
}

export interface Hints {
}

export interface Labels {
    readonly AccountNumber: string;
    readonly Title:         string;
}

Steps to Reproduce

  1. Paste the input in https://app.quicktype.io/#l=ts
  2. Observe output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0