pqina / filepond-plugin-file-rename

🏷 File rename plugin for FilePond
MIT License
6 stars 4 forks source link

Type of fileRenameFunction is wrong? #20

Open Gabiruti opened 10 months ago

Gabiruti commented 10 months ago

I was trying to use fileRenameFunction with a promise on angular and i was getting this error:

Type '(file: { basename: string; extension: string; name: string; }) => Promise' is not assignable to type '((options: { basename: string; extension: string; name: string; }) => string) | Promise'. Type '(file: { basename: string; extension: string; name: string; }) => Promise' is not assignable to type '(options: { basename: string; extension: string; name: string; }) => string'. Type 'Promise' is not assignable to type 'string'.ts(2322) ui-upload-order.component.ts(52, 33): Did you mean to call this expression?

so i changed the type of the function to:

// @ts-ignore
import { FilePondOptions } from "filepond";

declare module "filepond" {
    export interface FilePondOptions {
        /** Enable or disable file renaming */
        allowFileRename?: boolean;

        /** A function that receives an objecting containing file information like basename, extension and name. It should return either a string value or a Promise that resolves with a string value. */
        fileRenameFunction?:
        | undefined
        | null
        | ((options: {
            basename: string;
            extension: string;
            name: string;
        }) => string | Promise<string>);
    }
}

instead of:

// @ts-ignore
import { FilePondOptions } from "filepond";

declare module "filepond" {
    export interface FilePondOptions {
        /** Enable or disable file renaming */
        allowFileRename?: boolean;

        /** A function that receives an objecting containing file information like basename, extension and name. It should return either a string value or a Promise that resolves with a string value. */
        fileRenameFunction?:
        | undefined
        | null
        | ((options: {
            basename: string;
            extension: string;
            name: string;
        }) => string)
        | Promise<string>;
    }
}

and worked!

is it mean to be that way?