Skip to content
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

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@uppy/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class UIPlugin<TOptions extends PluginOptions = DefaultPluginOptions> ext
getTargetPlugin(target: PluginTarget): UIPlugin | undefined

// eslint-disable-next-line no-use-before-define
mount(target: PluginTarget, plugin: typeof UIPlugin): void
mount(target: PluginTarget, plugin: UIPlugin): void

render(state: Record<string, unknown>): void

Expand All @@ -126,6 +126,7 @@ export type PluginTarget =
| Element
| typeof BasePlugin
| typeof UIPlugin
| BasePlugin
Comment on lines 127 to +129
Copy link
Member

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>?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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!

Copy link
Member Author

@aduh95 aduh95 Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, typeof doesn't seem to behave as we are trying to make it behave: https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1oA9oF5oAYDcK0AnlrgQL5JKiQwAi0ApmgC6MB2AJjPApdeCjQAookKoM2AIwFUqEtgDMFFEhZEADo2gAVHKXVaA9gDM40AD7RDjU9DprN2nVINO7sAjd0AmN8bM6AiRkYCN2CBZrRkicAC5dfWxYanDI6MipBL1SBzCIqLZIn2ykkSR+ZDlofPSilnjdV2TUgoyWLKbc1rqYlhLE0mEKqiq5WsK+xp0-bon2zpnSFPn6gZzsYf4kIA

EDIT: turns out TS applies the "if it walk like a duck and quack like a duck, …" principle, so the above is expected.


export interface Locale<TNames extends string = string> {
strings: LocaleStrings<TNames>
Expand Down