fine-uploader icon indicating copy to clipboard operation
fine-uploader copied to clipboard

Incorrect TypeScript types for S3 customHeaders

Open bradleyayers opened this issue 7 years ago • 3 comments

Type of issue

  • [x] Bug report
  • [ ] Feature request

Uploader type

  • [ ] Traditional
  • [x] S3
  • [x] Azure

Current:

/**
 * type for S3's customHeaders function
 */
export interface S3CustomHeaderFunction {
    (id: number): void;
}

[snip]

/**
 * Additional headers sent along with each signature request.
 *
 * If you declare a function as the value, the associated file's ID will be passed to your function when it is invoked
 *
 * @default `{}`
 */
customHeaders?: any | S3CustomHeaderFunction;

The type should really be something like this:

customHeaders?: 
  | { [headerName: string]: string }
  | ((fileId: number) => { [headerName: string]: string });

bradleyayers avatar Mar 28 '18 21:03 bradleyayers

Is this working for you?

customHeaders?: 
  | { [headerName: string]: string }
  | (fileId: number) => { [headerName: string]: string };

Isn't there an extra | at the beginning or I'm not reading it right

singhjusraj avatar Mar 30 '18 01:03 singhjusraj

And I'm seeing some issues here

fu-type-error

singhjusraj avatar Mar 30 '18 01:03 singhjusraj

Isn't there an extra | at the beginning or I'm not reading it right

TypeScript has supported leading | for a while, see https://github.com/Microsoft/TypeScript/issues/12071. It was purely a stylistic choice from me to try and visually separate the two items of the union.

I'm going to wait for #1989 before raising a PR for this.

And I'm seeing some issues here

Thanks I was missing some parenthesis around the function, I've updated the snippet.

bradleyayers avatar Mar 30 '18 07:03 bradleyayers