openapi-typescript
openapi-typescript copied to clipboard
Union type for `error` disappears in typescript-fetch v0.10
Description
The union type for the error object returned by fetch has changed in typescript-fetch v0.10 and later versions.
Reproduction
I updated typescript-fetch to v0.10.1.
After the update, the type inference for the error object returned by fetch changed as follows:
Before v0.9.7
-
const error: { message: string } | Record<string, never> | undefined
v0.10.0 and Later
-
const error: { message: string } | undefined
OpenAPI YAML
I change the error response based on the type of error. For example, in the case of a 404 error, only a message is returned. For a 422 error, error messages are returned for each field.
# Partial YAML
responses:
'404':
description: NotFound
content:
application/json:
schema:
type: object
properties:
message:
type: string
required:
- message
'422':
description: Bad parameters
content:
application/json:
schema:
title: ''
type: object
properties:
errors:
type: object
properties: {}
required:
- errors
Expected result
It would be great if the error type could be the same as in previous versions:
const error: { message: string } | Record<string, never> | undefined
Checklist
- [ ] I’m willing to open a PR (see CONTRIBUTING.md)