Skip to content

Numeric status codes #380

Closed
Closed
@jankuca

Description

@jankuca

Hello, I really like this library but I had to fork it to be able to actually use it.

My issue is that the responses object lists the response status codes as strings. I need to be able to use numeric values in my codebase and I am not able to check them against the generated TS types.


My solution was to replace the { [statusCode]: responseBodies } object with a discriminated union:

responses:
  | { statusCode: 200, bodies:  }
  | { statusCode: 202, bodies:  }
  | { statusCode: 400, bodies:  }

I can get a numeric enum from that simply by using responses['statusCode'].


I've also noticed that TS allows actual numeric keys such as { 200: … } (instead of { "200": … }) so that could be enough.

Would such a change be acceptable? What is the actual reason the keys are strings anyway?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions