Skip to content

Commit

Permalink
typescript: fix uppy package use with allowSyntheticImports: false
Browse files Browse the repository at this point in the history
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
  • Loading branch information
goto-bus-stop committed Apr 1, 2019
1 parent 6cc7c00 commit 5709647
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
16 changes: 8 additions & 8 deletions packages/@uppy/aws-s3-multipart/types/aws-s3-multipart-tests.ts
Original file line number Diff line number Diff line change
@@ -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
},
});
}
6 changes: 3 additions & 3 deletions packages/@uppy/aws-s3/types/aws-s3-tests.ts
Original file line number Diff line number Diff line change
@@ -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
}
});
}
6 changes: 3 additions & 3 deletions packages/@uppy/dashboard/types/dashboard-tests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Uppy from '@uppy/core';
import Dashboard from '../';
import Uppy = require('@uppy/core')
import Dashboard = require('../')

{
const uppy = Uppy()
uppy.use(Dashboard, {
target: 'body'
})

const plugin = <Dashboard>uppy.getPlugin('Dashboard')
const plugin = uppy.getPlugin('Dashboard') as Dashboard
plugin.openModal()
plugin.isModalOpen() // $ExpectType boolean
plugin.closeModal()
Expand Down
28 changes: 14 additions & 14 deletions packages/@uppy/transloadit/types/transloadit-tests.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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: {} }
}
});
})
}
22 changes: 12 additions & 10 deletions test/endtoend/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"types": [],
"noEmit": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowSyntheticDefaultImports": false,
"strictFunctionTypes": true,
"forceConsistentCasingInFileNames": true
},
Expand Down

0 comments on commit 5709647

Please sign in to comment.