Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinction between nullable and optional #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GerritPlehn
Copy link

Hi! Similar to #21 when using this library to generate TS types, it's often useful to make a distinction between nullable and optional fields.
I'm looking for feedback on this PR as I'm very new to Rust. Currently not all tests are passing and before investing more time I'd like to know if the approach I took is ok.

Input

{
  "a": [{ "nullable": 1 }, { "nullable": null }],
  "b": [
    {
      "optional": 1,
      "always": true
    },
    {
      "always": true
    }
  ],
  "c": [
    {
      "optionalNullable": 1,
      "always": true
    },
    {
      "optionalNullable": null,
      "always": true
    },
    {
      "always": true
    }
  ]
}

Before the changes

export interface A {
    nullable?: number;
}

export interface B {
    optional?: number;
    always: boolean;
}

export interface C {
    optionalNullable?: number;
    always: boolean;
}

After the changes

export interface A {
    nullable: number | null;
}

export interface B {
    optional?: number;
    always: boolean;
}

export interface C {
    optionalNullable?: number | null;
    always: boolean;
}

@evestera
Copy link
Owner

Thank you for the PR. Looks reasonable at first glance, but it's been a while since I worked on this project, so will need to re-familiarize myself with the project a bit before I consider merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants