From 5709647728bec820b0203da83c299d3456236fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 1 Apr 2019 11:47:12 +0200 Subject: [PATCH] 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 --- .../types/aws-s3-multipart-tests.ts | 16 +++++------ packages/@uppy/aws-s3/types/aws-s3-tests.ts | 6 ++-- .../@uppy/dashboard/types/dashboard-tests.ts | 6 ++-- .../transloadit/types/transloadit-tests.ts | 28 +++++++++---------- test/endtoend/typescript/main.ts | 22 ++++++++------- tsconfig.json | 2 +- 6 files changed, 41 insertions(+), 39 deletions(-) diff --git a/packages/@uppy/aws-s3-multipart/types/aws-s3-multipart-tests.ts b/packages/@uppy/aws-s3-multipart/types/aws-s3-multipart-tests.ts index 6742e5f262..64e300bbcd 100644 --- a/packages/@uppy/aws-s3-multipart/types/aws-s3-multipart-tests.ts +++ b/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 }, }); } diff --git a/packages/@uppy/aws-s3/types/aws-s3-tests.ts b/packages/@uppy/aws-s3/types/aws-s3-tests.ts index 0929ea364b..3ca8e591bf 100644 --- a/packages/@uppy/aws-s3/types/aws-s3-tests.ts +++ b/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 } }); } diff --git a/packages/@uppy/dashboard/types/dashboard-tests.ts b/packages/@uppy/dashboard/types/dashboard-tests.ts index b271989aa7..956859c608 100644 --- a/packages/@uppy/dashboard/types/dashboard-tests.ts +++ b/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 = uppy.getPlugin('Dashboard') + const plugin = uppy.getPlugin('Dashboard') as Dashboard plugin.openModal() plugin.isModalOpen() // $ExpectType boolean plugin.closeModal() diff --git a/packages/@uppy/transloadit/types/transloadit-tests.ts b/packages/@uppy/transloadit/types/transloadit-tests.ts index 03477d4ded..ce3a775330 100644 --- a/packages/@uppy/transloadit/types/transloadit-tests.ts +++ b/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: {} } } - }); + }) } diff --git a/test/endtoend/typescript/main.ts b/test/endtoend/typescript/main.ts index fedf7f1441..656a1a2b24 100644 --- a/test/endtoend/typescript/main.ts +++ b/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', diff --git a/tsconfig.json b/tsconfig.json index dfe3a66e51..e38bb81a2d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "types": [], "noEmit": true, "esModuleInterop": true, - "allowSyntheticDefaultImports": true, + "allowSyntheticDefaultImports": false, "strictFunctionTypes": true, "forceConsistentCasingInFileNames": true },