Skip to content

Commit

Permalink
@uppy/code: allow plugins to type PluginState (#4872)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Jan 18, 2024
1 parent 93053e3 commit 218c6d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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

0 comments on commit 218c6d1

Please sign in to comment.