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

Typescript: Argument of type 'this' is not assignable to parameter of type 'typeof UIPlugin' #3618

Closed
uncvrd opened this issue Apr 3, 2022 · 1 comment · Fixed by #4332
Closed
Assignees
Labels
Bug Types Issues relating to the Typescript definition files

Comments

@uncvrd
Copy link

uncvrd commented Apr 3, 2022

In an attempt to create a custom Dashboard plugin using Typescript, the mount method requires passing this as the second parameter. However, I receive the following error:

Argument of type 'this' is not assignable to parameter of type 'typeof UIPlugin'.
  Property 'prototype' is missing in type 'UppyDashboardPlugin' but required in type 'typeof UIPlugin'.

My class is essentially a barebones Dashboard react component taken from the @uppy/react library, but just in Typescript:

class UppyDashboardPlugin extends UIPlugin {

    opts: DefaultPluginOptions;

    constructor(uppy: Uppy, opts?: DefaultPluginOptions | undefined) {
        super(uppy, opts);
        this.id = opts?.id ?? "UppyDashboardPlugin";
        this.type = "dashboard";

        this.opts = opts ?? {};
    }

    install = () => {
        const { target } = this.opts;
        if (!!target) {
            this.mount(target, this); <-- CODE ERRORS ON THIS LINE. Obviously if i @ts-ignore it, the component works but would rather avoid that.
        }
    }
}

Also just FYI, the documentation states that you only need to pass a target with mount, but the typings in Typescript require two args. (target and the this of the class): https://uppy.io/docs/writing-plugins/#BasePlugin

EDIT:

Here's a codesandbox reproduction: https://codesandbox.io/s/fancy-lake-bovb0t?file=/src/Dashboard.tsx

@Murderlon Murderlon added Types Issues relating to the Typescript definition files and removed Triage labels Apr 4, 2022
@Murderlon
Copy link
Member

Hi, thanks for the reproducible example. Are you willing to contribute a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Types Issues relating to the Typescript definition files
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants