Skip to content

Fix Record<string, never> appearing in discriminator union #1248

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
Jul 25, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Jul 25, 2023

Changes

If a discriminator has type: "object" in it, it would completely change the output.

Unfortunately, fixing this did cause some ⚠️ minor breaking changes in generated types. But I’m hopeful the change is an improvement and not a regression, as the new types should yield better TS inference.

How to Review

Tests should pass.

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (only applicable for openapi-typescript)

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2023

🦋 Changeset detected

Latest commit: d233633

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@drwpow drwpow force-pushed the no-empty-object-union branch from 11e4fcf to 69fc7ef Compare July 25, 2023 18:18
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 25, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: d233633
Status: ✅  Deploy successful!
Preview URL: https://c96ff172.openapi-ts.pages.dev
Branch Preview URL: https://no-empty-object-union.openapi-ts.pages.dev

View logs

@drwpow drwpow force-pushed the no-empty-object-union branch from 69fc7ef to 358c55c Compare July 25, 2023 18:19
@@ -4,8 +4,8 @@ module.exports = {
parserOptions: {
project: ["./tsconfig.json"],
},
extends: ["eslint:recommended", "plugin:@typescript-eslint/strict"],
plugins: ["@typescript-eslint", "prettier"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/strict", "plugin:vitest/recommended"],
Copy link
Contributor Author

@drwpow drwpow Jul 25, 2023

Choose a reason for hiding this comment

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

Minor linting improvements to test files (mostly just catches test.only() from lingering, which can be easy to forget to remove)

@drwpow drwpow force-pushed the no-empty-object-union branch from 358c55c to f86107d Compare July 25, 2023 18:20
@@ -34143,7 +34143,7 @@ export interface components {
public?: boolean;
/** Format: uri-template */
pulls_url: string;
pushed_at: number | string;
pushed_at: number | string | null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🐛 This is a bugfix

@@ -73010,7 +73010,7 @@ export interface components {
files?: string[];
bin?: Record<string, never>;
man?: Record<string, never>;
directories?: string | Record<string, never>;
directories?: string | Record<string, never> | null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems wrong, but is generated from:

oneOf:
  - type: string
  - type: object
nullable: true

This is correct, at least as long as we generate Record<string, never> for empty objects (with no additionaalProperties)

@drwpow drwpow force-pushed the no-empty-object-union branch from f86107d to 5d11dea Compare July 25, 2023 18:33
@drwpow drwpow force-pushed the no-empty-object-union branch from 5d11dea to d233633 Compare July 25, 2023 18:58
@drwpow drwpow merged commit c145f5f into main Jul 25, 2023
@drwpow drwpow deleted the no-empty-object-union branch July 25, 2023 19:01
@github-actions github-actions bot mentioned this pull request Jul 25, 2023
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.

1 participant