Procházet zdrojové kódy

typescript: fix uppy package use with allowSyntheticImports: false

Synthetic default imports allow you to `import X from 'x'` if `'x'` is a
CommonJS module. Our `uppy` package relied on that (probably forgot to
update it in a previous patch). If users had set
`allowSyntheticDefaultImports: false`, they would not be able to use the
`uppy` package.

We should at some point go through the typings again and set everything
to the tightest options, because that'll work with the widest array of
users, but for now let's just unbreak this particular case.

Fixes #1395
Renée Kooi před 6 roky
rodič
revize
5709647728

+ 8 - 8
packages/@uppy/aws-s3-multipart/types/aws-s3-multipart-tests.ts

@@ -1,34 +1,34 @@
-import Uppy, { UppyFile } from '@uppy/core';
-import AwsS3Multipart, { AwsS3Part } from '../';
+import Uppy = require('@uppy/core');
+import AwsS3Multipart = require('../');
 
 {
   const uppy = Uppy();
   uppy.use(AwsS3Multipart, {
     createMultipartUpload(file) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
     },
     listParts(file, opts) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       opts.uploadId // $ExpectType string
       opts.key // $ExpectType string
     },
     prepareUploadPart(file, part) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       part.uploadId // $ExpectType string
       part.key // $ExpectType string
       part.body // $ExpectType Blob
       part.number // $ExpectType number
     },
     abortMultipartUpload(file, opts) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       opts.uploadId // $ExpectType string
       opts.key // $ExpectType string
     },
     completeMultipartUpload(file, opts) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       opts.uploadId // $ExpectType string
       opts.key // $ExpectType string
-      opts.parts[0] // $ExpectType AwsS3Part
+      opts.parts[0] // $ExpectType AwsS3Multipart.AwsS3Part
     },
   });
 }

+ 3 - 3
packages/@uppy/aws-s3/types/aws-s3-tests.ts

@@ -1,11 +1,11 @@
-import Uppy, { UppyFile } from '@uppy/core';
-import AwsS3 from '../';
+import Uppy = require('@uppy/core');
+import AwsS3 = require('../');
 
 {
   const uppy = Uppy();
   uppy.use(AwsS3, {
     getUploadParameters(file) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
     }
   });
 }

+ 3 - 3
packages/@uppy/dashboard/types/dashboard-tests.ts

@@ -1,5 +1,5 @@
-import Uppy from '@uppy/core';
-import Dashboard from '../';
+import Uppy = require('@uppy/core')
+import Dashboard = require('../')
 
 {
   const uppy = Uppy()
@@ -7,7 +7,7 @@ import Dashboard from '../';
     target: 'body'
   })
 
-  const plugin = <Dashboard>uppy.getPlugin('Dashboard')
+  const plugin = uppy.getPlugin('Dashboard') as Dashboard
   plugin.openModal()
   plugin.isModalOpen() // $ExpectType boolean
   plugin.closeModal()

+ 14 - 14
packages/@uppy/transloadit/types/transloadit-tests.ts

@@ -1,11 +1,11 @@
-import Uppy, { UppyFile } from '@uppy/core';
-import Transloadit  from '../';
+import Uppy = require('@uppy/core')
+import Transloadit = require('../')
 
 {
-  const uppy = Uppy();
+  const uppy = Uppy()
   uppy.use(Transloadit, {
     getAssemblyOptions(file) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
     },
     waitForEncoding: false,
     waitForMetadata: true,
@@ -14,40 +14,40 @@ import Transloadit  from '../';
       auth: { key: 'abc' },
       steps: {}
     }
-  });
+  })
 }
 
 {
-  const uppy = Uppy();
+  const uppy = Uppy()
   // $ExpectError
-  uppy.use(Transloadit, { waitForEncoding: null });
+  uppy.use(Transloadit, { waitForEncoding: null })
   // $ExpectError
-  uppy.use(Transloadit, { waitForMetadata: null });
+  uppy.use(Transloadit, { waitForMetadata: null })
 }
 
 {
-  const uppy = Uppy();
+  const uppy = Uppy()
   // $ExpectError
-  uppy.use(Transloadit, { params: {} });
+  uppy.use(Transloadit, { params: {} })
   // $ExpectError
-  uppy.use(Transloadit, { params: { auth: {} } });
+  uppy.use(Transloadit, { params: { auth: {} } })
   // $ExpectError
   uppy.use(Transloadit, {
     params: {
       auth: { key: null }
     }
-  });
+  })
   // $ExpectError
   uppy.use(Transloadit, {
     params: {
       auth: { key: 'abc' },
       steps: 'test'
     }
-  });
+  })
   uppy.use(Transloadit, {
     params: {
       auth: { key: 'abc' },
       steps: { name: {} }
     }
-  });
+  })
 }

+ 12 - 10
test/endtoend/typescript/main.ts

@@ -1,18 +1,20 @@
 import 'es6-promise/auto'
 import 'whatwg-fetch'
-import Uppy = require('@uppy/core')
-import Dashboard = require('@uppy/dashboard')
-import Instagram = require('@uppy/instagram')
-import Dropbox = require('@uppy/dropbox')
-import GoogleDrive = require('@uppy/google-drive')
-import Url = require('@uppy/url')
-import Webcam = require('@uppy/webcam')
-import Tus = require('@uppy/tus')
-import Form = require('@uppy/form')
+import {
+  Core,
+  Dashboard,
+  Instagram,
+  Dropbox,
+  GoogleDrive,
+  Url,
+  Webcam,
+  Tus,
+  Form
+} from 'uppy'
 
 const TUS_ENDPOINT = 'https://master.tus.io/files/'
 
-const uppy = Uppy({
+const uppy = Core({
   debug: true,
   meta: {
     username: 'John',

+ 1 - 1
tsconfig.json

@@ -12,7 +12,7 @@
     "types": [],
     "noEmit": true,
     "esModuleInterop": true,
-    "allowSyntheticDefaultImports": true,
+    "allowSyntheticDefaultImports": false,
     "strictFunctionTypes": true,
     "forceConsistentCasingInFileNames": true
   },