hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
651 stars 47 forks source link

Support for exactOptionalPropertyTypes in tsconfig.json #590

Closed DonnyVerduijn closed 1 month ago

DonnyVerduijn commented 1 month ago

Description

Currently, when "exactOptionalPropertyTypes" is enabled in tsconfig.json, the generated files cause TS errors, because formData for example, is provided even though its type is possibly undefined.

A workaround is to add an exclamation mark behind formData as seen in the following example. However it would be great if we would have a better OOTB solution for this problem.

  /**
   * Update firmware
   * @param data The data for the request.
   * @param data.formData Firmware file
   * @returns unknown success
   * @throws ApiError
   */
  public static postFirmware(
    data: PostFirmwareData = {}
  ): CancelablePromise<PostFirmwareResponse> {
    return __request(OpenAPI, {
      method: 'POST',
      url: '/firmware',
      formData: data.formData!,
      mediaType: 'multipart/form-data',
      errors: {
        500: 'server error',
      },
    });
  }
}
mrlubos commented 1 month ago

Let me get to this after clients are done

mrlubos commented 1 month ago

Hey, did you see the new Fetch API client? Wonder if that works for you

DonnyVerduijn commented 1 month ago

This problem is solved by using @hey-api/client-fetch. Closing.