Ver código fonte

Fix React `DashboardModal`'s `target` type (#3110)

Merlijn Vos 3 anos atrás
pai
commit
2ce0c8b4dc

+ 2 - 1
packages/@uppy/react/src/CommonTypes.d.ts

@@ -6,5 +6,6 @@ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
 // If I use the helper it doesn't work, I think because 'target' is not a `keyof T` while
 // the generic T is unknown, so will just use the expansion here
 type OmitTarget<T> = Pick<T, Exclude<keyof T, 'target'>>
-type WithBaseUppyProps<T> = T & { uppy: Uppy }
+
+export type WithBaseUppyProps<T> = T & { uppy: Uppy }
 export type ToUppyProps<T> = WithBaseUppyProps<OmitTarget<T>>

+ 10 - 5
packages/@uppy/react/src/Dashboard.d.ts

@@ -1,16 +1,21 @@
 import * as React from 'react'
 import type { DashboardOptions } from '@uppy/dashboard'
-import { Omit, ToUppyProps } from './CommonTypes'
+import { Omit, WithBaseUppyProps } from './CommonTypes'
 
 // This type is mapped into `DashboardProps` below so IntelliSense doesn't display this big mess of nested types
 type DashboardPropsInner = Omit<
-  ToUppyProps<DashboardOptions>,
+  WithBaseUppyProps<DashboardOptions>,
   // Remove the modal-only props
-  'animateOpenClose' | 'browserBackButtonClose' | 'inline' | 'onRequestCloseModal' | 'trigger'
-> & React.BaseHTMLAttributes<HTMLDivElement>
+  | 'animateOpenClose'
+  | 'browserBackButtonClose'
+  | 'inline'
+  | 'onRequestCloseModal'
+  | 'trigger'
+> &
+  React.BaseHTMLAttributes<HTMLDivElement>
 
 export type DashboardProps = {
-   [K in keyof DashboardPropsInner]: DashboardPropsInner[K]
+  [K in keyof DashboardPropsInner]: DashboardPropsInner[K]
 }
 
 /**

+ 1 - 4
packages/@uppy/react/src/DashboardModal.js

@@ -74,7 +74,7 @@ class DashboardModal extends React.Component {
   }
 }
 
-DashboardModal.propTypes = { // Only check this prop type in the browser.
+DashboardModal.propTypes = {
   target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any,
   open: PropTypes.bool,
   onRequestClose: PropTypes.func,
@@ -83,7 +83,4 @@ DashboardModal.propTypes = { // Only check this prop type in the browser.
   ...basePropTypes,
 }
 
-DashboardModal.defaultProps = {
-}
-
 module.exports = DashboardModal

+ 5 - 0
packages/@uppy/react/types/index.test-d.tsx

@@ -15,6 +15,10 @@ const uppy = new Uppy()
   }
 }
 
+{
+  expectError(<components.Dashboard target="body"/>)
+}
+
 // inline option should be removed from proptypes because it is always overridden
 // by the component
 {
@@ -45,6 +49,7 @@ const uppy = new Uppy()
 {
   const el = (
     <components.DashboardModal
+      target="body"
       uppy={uppy}
       open
       animateOpenClose