openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
556 stars 67 forks source link

Incorrect types generated for empty hash #162

Open tdeo opened 1 year ago

tdeo commented 1 year ago

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: https://github.com/horiuchi/dtsgenerator/issues/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 commented 1 year ago

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