New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@uppy/core: fix some types #4332
Conversation
| typeof BasePlugin | ||
| typeof UIPlugin | ||
| BasePlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have typeof BasePlugin
but also BasePlugin
? Should be perhaps be InstanceOf<typeof BasePlugin>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the nuances of that, I'd need to look it up. But basically what we were missing was that the user can either pass the plugin class, or a plugin instance. Can InstanceOf<>
target both at once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically I think it would satisfy both, but technically it means the initialized instance. Regardless, if we want to type the instance, there should at least be a InstanceOf
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BasePlugin
would target an instance of BasePlugin
(or any other subclass of BasePlugin
), why do we need the InstanceOf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot find name 'InstanceOf'
, also it doesn't seem to exist, or what am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try to replace both with this? I think it should be stricter than current attempt
https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs says that InstanceType<typeof C>
is C
though, what's stricter about it? I just tried in the playground, and it seems InstanceType
doesn't help us here: https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1oA9oF5oAYDcK0AnlrgQL4pIAuRADgKbQAqOpAkgHYTVifANm9BgB5ajAPYAzOAD4C4pswCMpWAuEsATGugAfaIulwCSZMAndqhhjxwAuFm2ycGAdzhILVmz2WPWNSRKM0JUbx5fagcWVRd3Twjraltqf1igkORUcMtIlLsAnVJXD1gvPOTU9OYdbHKQpCA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking. I remembered this helped me with typing tus-node-server, perhaps I remember wrong. This is okay then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1oA9oF5oAYDcK0AnlrgQL5JKiQwAi0ApmgC6MB2AJjPApdeCjQAookKoM2AIwFUqEtgDMFFEhZEADo2gAVHKXVaA9gDM40AD7RDjU9DprN2nVINO7sAjd0AmN8bM6AiRkYCN2CBZrRkicAC5dfWxYanDI6MipBL1SBzCIqLZIn2ykkSR+ZDlofPSilnjdV2TUgoyWLKbc1rqYlhLE0mEKqiq5WsK+xp0-bon2zpnSFPn6gZzsYf4kIAtypeof
doesn't seem to behave as we are trying to make it behave:
EDIT: turns out TS applies the "if it walk like a duck and quack like a duck, …" principle, so the above is expected.
| Package | Version | Package | Version | | -------------------- | ------- | -------------------- | ------- | | @uppy/audio | 1.1.0 | @uppy/onedrive | 3.1.0 | | @uppy/box | 2.1.0 | @uppy/provider-views | 3.1.0 | | @uppy/core | 3.1.0 | @uppy/screen-capture | 3.1.0 | | @uppy/dashboard | 3.3.0 | @uppy/unsplash | 3.1.0 | | @uppy/dropbox | 3.1.0 | @uppy/url | 3.2.0 | | @uppy/facebook | 3.1.0 | @uppy/utils | 5.1.3 | | @uppy/google-drive | 3.1.0 | @uppy/webcam | 3.3.0 | | @uppy/image-editor | 2.1.1 | @uppy/zoom | 2.1.0 | | @uppy/instagram | 3.1.0 | uppy | 3.6.0 | | @uppy/locales | 3.0.7 | | | - @uppy/locales: add missing entries after build (Murderlon) - @uppy/dashboard: update provider icon style (Alexander Zaytsev / #4345) - @uppy/core: fix uppy.resetProgress() (Artur Paikin / #4337) - @uppy/core: fix some types (Antoine du Hamel / #4332) - @uppy/core: Fixed type of State.info to match reality being an array of info objects (Marc Bennewitz / #4321) - @uppy/image-editor: Fix TypeScript error in image-editor types (Matthias Kunnen / #4334) - meta: improve `importFromUploadURLs` docs (Mikael Finstad / #4323) - @uppy/utils: workaround chrome crash (Mikael Finstad / #4310)
Fixes: #3618