Просмотр исходного кода

Merge pull request #1396 from transloadit/fix/yet-more-typescript

typescript: fix uppy package use with allowSyntheticImports: false
Artur Paikin 6 лет назад
Родитель
Сommit
c52dc24317

+ 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();
   const uppy = Uppy();
   uppy.use(AwsS3Multipart, {
   uppy.use(AwsS3Multipart, {
     createMultipartUpload(file) {
     createMultipartUpload(file) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
     },
     },
     listParts(file, opts) {
     listParts(file, opts) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       opts.uploadId // $ExpectType string
       opts.uploadId // $ExpectType string
       opts.key // $ExpectType string
       opts.key // $ExpectType string
     },
     },
     prepareUploadPart(file, part) {
     prepareUploadPart(file, part) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       part.uploadId // $ExpectType string
       part.uploadId // $ExpectType string
       part.key // $ExpectType string
       part.key // $ExpectType string
       part.body // $ExpectType Blob
       part.body // $ExpectType Blob
       part.number // $ExpectType number
       part.number // $ExpectType number
     },
     },
     abortMultipartUpload(file, opts) {
     abortMultipartUpload(file, opts) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       opts.uploadId // $ExpectType string
       opts.uploadId // $ExpectType string
       opts.key // $ExpectType string
       opts.key // $ExpectType string
     },
     },
     completeMultipartUpload(file, opts) {
     completeMultipartUpload(file, opts) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
       opts.uploadId // $ExpectType string
       opts.uploadId // $ExpectType string
       opts.key // $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();
   const uppy = Uppy();
   uppy.use(AwsS3, {
   uppy.use(AwsS3, {
     getUploadParameters(file) {
     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()
   const uppy = Uppy()
@@ -7,7 +7,7 @@ import Dashboard from '../';
     target: 'body'
     target: 'body'
   })
   })
 
 
-  const plugin = <Dashboard>uppy.getPlugin('Dashboard')
+  const plugin = uppy.getPlugin('Dashboard') as Dashboard
   plugin.openModal()
   plugin.openModal()
   plugin.isModalOpen() // $ExpectType boolean
   plugin.isModalOpen() // $ExpectType boolean
   plugin.closeModal()
   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, {
   uppy.use(Transloadit, {
     getAssemblyOptions(file) {
     getAssemblyOptions(file) {
-      file // $ExpectType UppyFile
+      file // $ExpectType Uppy.UppyFile
     },
     },
     waitForEncoding: false,
     waitForEncoding: false,
     waitForMetadata: true,
     waitForMetadata: true,
@@ -14,40 +14,40 @@ import Transloadit  from '../';
       auth: { key: 'abc' },
       auth: { key: 'abc' },
       steps: {}
       steps: {}
     }
     }
-  });
+  })
 }
 }
 
 
 {
 {
-  const uppy = Uppy();
+  const uppy = Uppy()
   // $ExpectError
   // $ExpectError
-  uppy.use(Transloadit, { waitForEncoding: null });
+  uppy.use(Transloadit, { waitForEncoding: null })
   // $ExpectError
   // $ExpectError
-  uppy.use(Transloadit, { waitForMetadata: null });
+  uppy.use(Transloadit, { waitForMetadata: null })
 }
 }
 
 
 {
 {
-  const uppy = Uppy();
+  const uppy = Uppy()
   // $ExpectError
   // $ExpectError
-  uppy.use(Transloadit, { params: {} });
+  uppy.use(Transloadit, { params: {} })
   // $ExpectError
   // $ExpectError
-  uppy.use(Transloadit, { params: { auth: {} } });
+  uppy.use(Transloadit, { params: { auth: {} } })
   // $ExpectError
   // $ExpectError
   uppy.use(Transloadit, {
   uppy.use(Transloadit, {
     params: {
     params: {
       auth: { key: null }
       auth: { key: null }
     }
     }
-  });
+  })
   // $ExpectError
   // $ExpectError
   uppy.use(Transloadit, {
   uppy.use(Transloadit, {
     params: {
     params: {
       auth: { key: 'abc' },
       auth: { key: 'abc' },
       steps: 'test'
       steps: 'test'
     }
     }
-  });
+  })
   uppy.use(Transloadit, {
   uppy.use(Transloadit, {
     params: {
     params: {
       auth: { key: 'abc' },
       auth: { key: 'abc' },
       steps: { name: {} }
       steps: { name: {} }
     }
     }
-  });
+  })
 }
 }

+ 46 - 25
packages/uppy/types/index.d.ts

@@ -1,40 +1,61 @@
-// Type definitions for uppy 0.25.5
+// Type definitions for uppy
 // Project: https://uppy.io
 // Project: https://uppy.io
 // Definitions by: taoqf <https://github.com/taoqf>
 // Definitions by: taoqf <https://github.com/taoqf>
 
 
 // Core
 // Core
-export { default as Core } from '@uppy/core';
+import Core = require('@uppy/core');
+export { Core };
 
 
 // Stores
 // Stores
 import DefaultStore = require('@uppy/store-default');
 import DefaultStore = require('@uppy/store-default');
-export { DefaultStore };  // this is weird: exporting a function as something that sounds like a class name!
-// do we really mean what the line above says?
-export { default as ReduxStore } from '@uppy/store-redux';
+export { DefaultStore };
+import ReduxStore = require('@uppy/store-redux');
+export { ReduxStore };
 
 
 // UI plugins
 // UI plugins
-export { default as Dashboard } from '@uppy/dashboard';
-export { default as DragDrop } from '@uppy/drag-drop';
-export { default as FileInput } from '@uppy/file-input';
-export { default as Informer } from '@uppy/informer';
-export { default as ProgressBar } from '@uppy/progress-bar';
-export { default as StatusBar } from '@uppy/status-bar';
+import Dashboard = require('@uppy/dashboard');
+export { Dashboard };
+import DragDrop = require('@uppy/drag-drop');
+export { DragDrop };
+import FileInput = require('@uppy/file-input');
+export { FileInput };
+import Informer = require('@uppy/informer');
+export { Informer };
+import ProgressBar = require('@uppy/progress-bar');
+export { ProgressBar };
+import StatusBar = require('@uppy/status-bar');
+export { StatusBar };
 
 
 // Acquirers
 // Acquirers
-export { default as Dropbox } from '@uppy/dropbox';
-export { default as GoogleDrive } from '@uppy/google-drive';
-export { default as Instagram } from '@uppy/instagram';
-export { default as Url } from '@uppy/url';
-export { default as Webcam } from '@uppy/webcam';
+import Dropbox = require('@uppy/dropbox');
+export { Dropbox };
+import GoogleDrive = require('@uppy/google-drive');
+export { GoogleDrive };
+import Instagram = require('@uppy/instagram');
+export { Instagram };
+import Url = require('@uppy/url');
+export { Url };
+import Webcam = require('@uppy/webcam');
+export { Webcam };
 
 
 // Uploaders
 // Uploaders
-export { default as AwsS3 } from '@uppy/aws-s3';
-export { default as AwsS3Multipart } from '@uppy/aws-s3-multipart';
-export { default as Transloadit } from '@uppy/transloadit';
-export { default as Tus } from '@uppy/tus';
-export { default as XHRUpload } from '@uppy/xhr-upload';
+import AwsS3 = require('@uppy/aws-s3');
+export { AwsS3 };
+import AwsS3Multipart = require('@uppy/aws-s3-multipart');
+export { AwsS3Multipart };
+import Transloadit = require('@uppy/transloadit');
+export { Transloadit };
+import Tus = require('@uppy/tus');
+export { Tus };
+import XHRUpload = require('@uppy/xhr-upload');
+export { XHRUpload };
 
 
 // Miscellaneous
 // Miscellaneous
-export { default as Form } from '@uppy/form';
-export { default as GoldenRetriever } from '@uppy/golden-retriever';
-export { default as ReduxDevTools } from '@uppy/redux-dev-tools';
-export { default as ThumbnailGenerator } from '@uppy/thumbnail-generator';
+import Form = require('@uppy/form');
+export { Form };
+import GoldenRetriever = require('@uppy/golden-retriever');
+export { GoldenRetriever };
+import ReduxDevTools = require('@uppy/redux-dev-tools');
+export { ReduxDevTools };
+import ThumbnailGenerator = require('@uppy/thumbnail-generator');
+export { ThumbnailGenerator };

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

@@ -1,18 +1,20 @@
 import 'es6-promise/auto'
 import 'es6-promise/auto'
 import 'whatwg-fetch'
 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 TUS_ENDPOINT = 'https://master.tus.io/files/'
 
 
-const uppy = Uppy({
+const uppy = Core({
   debug: true,
   debug: true,
   meta: {
   meta: {
     username: 'John',
     username: 'John',

+ 1 - 1
tsconfig.json

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