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

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

GerritPlehn
Copy link
Contributor

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.

@evestera
Copy link
Owner

Thank you for the PR and sorry this took so long to merge. Actually ended up experimenting with your changes as part of a bigger refactor locally, just never ended up getting to a clean, working state I was entirely happy with. But I think it's time to focus on progress over perfection. So thank you again for the PR, and welcome as a contributor.

@evestera evestera merged commit b3ecdc7 into evestera:master Feb 27, 2025
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