Browse Source

@uppy/companion-client: do not allow boolean `RequestOptions` (#5198)

Mikael Finstad 11 months ago
parent
commit
ba2fb67afe

+ 3 - 0
docs/guides/migration-guides.md

@@ -30,6 +30,9 @@ These cover all the major Uppy versions and how to migrate to them.
   class you don’t need to do anything.
 - Remove deprecated options `serverUrl` and `serverPattern` (they were merely
   defined in Typescript, not in use).
+- `RequestClient` methods `get`, `post`, `delete` no longer accepts a boolean as
+  the third argument. Instead, pass `{ skipPostResponse: true | false }`. This
+  won’t affect you unless you’ve been using `RequestClient`.
 
 ## Migrate from Robodog to Uppy plugins
 

+ 3 - 16
packages/@uppy/companion-client/src/RequestClient.ts

@@ -27,10 +27,6 @@ export type Opts = {
   companionKeysParams?: Record<string, string>
 }
 
-type _RequestOptions =
-  | boolean // TODO: remove this on the next major
-  | RequestOptions
-
 // Remove the trailing slash so we can always safely append /xyz.
 function stripSlash(url: string) {
   return url.replace(/\/$/, '')
@@ -195,33 +191,24 @@ export default class RequestClient<M extends Meta, B extends Body> {
 
   async get<PostBody>(
     path: string,
-    options?: _RequestOptions,
+    options?: RequestOptions,
   ): Promise<PostBody> {
-    // TODO: remove boolean support for options that was added for backward compatibility.
-    // eslint-disable-next-line no-param-reassign
-    if (typeof options === 'boolean') options = { skipPostResponse: options }
     return this.request({ ...options, path })
   }
 
   async post<PostBody>(
     path: string,
     data: Record<string, unknown>,
-    options?: _RequestOptions,
+    options?: RequestOptions,
   ): Promise<PostBody> {
-    // TODO: remove boolean support for options that was added for backward compatibility.
-    // eslint-disable-next-line no-param-reassign
-    if (typeof options === 'boolean') options = { skipPostResponse: options }
     return this.request<PostBody>({ ...options, path, method: 'POST', data })
   }
 
   async delete<T>(
     path: string,
     data?: Record<string, unknown>,
-    options?: _RequestOptions,
+    options?: RequestOptions,
   ): Promise<T> {
-    // TODO: remove boolean support for options that was added for backward compatibility.
-    // eslint-disable-next-line no-param-reassign
-    if (typeof options === 'boolean') options = { skipPostResponse: options }
     return this.request({ ...options, path, method: 'DELETE', data })
   }