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

Incorrect types generated for empty hash #162

Open
tdeo opened this issue Jul 12, 2023 · 1 comment
Open

Incorrect types generated for empty hash #162

tdeo opened this issue Jul 12, 2023 · 1 comment

Comments

@tdeo
Copy link

tdeo commented Jul 12, 2023

Hello,

I was looking into suspicious output when having the following OpenApi schema:

type: object
additionalProperties: false

This means I expect the object to be an empty hash. Unfortunately, I'm getting the following output in my autogenerated axios client types:

{ [key: string]: any }

I'd rather have { [key: string]: never }, or Record<any, never>. That's important in the following scenario:

oneOf:
  - type: object
    additionalProperties: false
    properties:
      foo:
        type: string
    required: 
      - foo
  - type: object
    additionalProperties: false

And in TS, I'd like to check for if ('foo' in obj) to tell apart both cases and have proper type inference within the block, but since the generated type ends up being { foo: string } | { [key: string]: any }, TS can't know which case it is.

I found the following upstream issue which may also be related: horiuchi/dtsgenerator#525, but I'm also seeing that you use your own fork of this lib which seems to be lagging significantly behind.

Would you have any recommendation about how to get this adressed?

I would be willing to try to work on that upstream issue, and if so would you be updating your fork with the upstream?

Thanks

@anttiviljami
Copy link
Member

Sure, that’d be great. Glad to backport and bring the upstream dtsgen up to date if it improves the generated types 💪

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

No branches or pull requests

2 participants