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/code: allow plugins to type PluginState #4872

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions packages/@uppy/core/src/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class BasePlugin<
Opts extends PluginOpts,
M extends Meta,
B extends Body,
PluginState extends Record<string, unknown> = Record<string, unknown>,
> {
uppy: Uppy<M, B>

Expand All @@ -47,12 +48,12 @@ export default class BasePlugin<
this.opts = opts ?? {}
}

getPluginState(): Record<string, unknown> {
getPluginState(): PluginState {
const { plugins } = this.uppy.getState()
return plugins?.[this.id] || {}
return (plugins?.[this.id] || {}) as PluginState
}

setPluginState(update: unknown): void {
setPluginState(update?: Partial<PluginState>): void {
if (!update) return
const { plugins } = this.uppy.getState()

Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class UIPlugin<
Opts extends UIPluginOptions,
M extends Meta,
B extends Body,
> extends BasePlugin<Opts, M, B> {
PluginState extends Record<string, unknown> = Record<string, unknown>,
> extends BasePlugin<Opts, M, B, PluginState> {
#updateUI: (state: Partial<State<M, B>>) => void

isTargetDOMEl: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type UnknownProviderPlugin<M extends Meta, B extends Body> = UnknownPlugin<
}

// The user facing type for UppyFile used in uppy.addFile() and uppy.setOptions()
type MinimalRequiredUppyFile<M extends Meta, B extends Body> = Required<
export type MinimalRequiredUppyFile<M extends Meta, B extends Body> = Required<
Pick<UppyFile<M, B>, 'name' | 'data' | 'type' | 'source'>
> &
Partial<
Expand Down
Loading