Skip to content

Fix readonly nullable properties edge case #1036

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

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

mtth
Copy link
Contributor

@mtth mtth commented Feb 23, 2023

Changes

The current logic generates invalid TypeScript code for nullable array properties which include at least one union (potentially nested) when the immutableTypes option is set.

Simple example:

  type: array
  nullable: true
  items:
    oneOf:
      - type: number
      - type: string

Generated code before and after this PR:

  readonly before: readonly ((number | string)[]) | null; // Invalid
  readonly after: (readonly (number | string)[]) | null; // OK

How to Review

The added unit-test provides another example. You could also compile the GitHub spec with immutability enabled: it should fail without the fix and succeed with it.

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (if applicable)

The current logic generates invalid TypeScript code with the
`immutableTypes` option for nullable properties which include at least
one union (potentially nested):

Simple example:

  type: array
  nullable: true
  items:
    oneOf:
      - type: number
      - type: string

Generated code before and after this PR:

  readonly before: readonly ((number | string)[]) | null; // Invalid
  readonly after: (readonly (number | string)[]) | null; // OK
@mtth mtth force-pushed the readonly-nullable branch from 6b51ad9 to b924dbd Compare February 23, 2023 16:49
Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome fix, thank you!

@drwpow drwpow merged commit 754b872 into openapi-ts:main Mar 10, 2023
@drwpow
Copy link
Contributor

drwpow commented Mar 10, 2023

@all-contributors please add @mtth for code, bug, test

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @mtth! 🎉

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