Skip to content

add Typescript definitions#199

Merged
seanadkinson merged 2 commits into
odysseyscience:masterfrom
jakemmarsh:patch-1
Jan 17, 2020
Merged

add Typescript definitions#199
seanadkinson merged 2 commits into
odysseyscience:masterfrom
jakemmarsh:patch-1

Conversation

@jakemmarsh

Copy link
Copy Markdown
Contributor

No description provided.

@azizhk

azizhk commented Feb 15, 2019

Copy link
Copy Markdown

Hi @jakemmarsh, I made a few changes to reflect the code as correctly as possible:

declare module 'react-s3-uploader' {
  import { Component } from 'react';
  import { Omit } from 'utility-types';
  import { OutgoingHttpHeaders } from "http";
  import { ReactS3UploaderOptions } from 'react-s3-uploader/s3upload';

  export type ReactS3UploaderProps = Omit<ReactS3UploaderOptions, 'files' | 'fileElement' | 'onFinishS3Put'> & {
    accept?: string;
    autoUpload?: boolean;
    inputRef?: React.Ref<HTMLInputElement> | ((ref: HTMLInputElement) => void);
    onFinish?: ReactS3UploaderOptions['onFinishS3Put'];
  }

  class ReactS3Uploader extends React.Component<ReactS3UploaderProps> { }

  export default ReactS3Uploader;
}

declare module 'react-s3-uploader/s3upload' {
  type UploadStates = 'Waiting' | 'Uploading' | 'Finalizing' | 'Upload completed'
  interface SignURLResponse {
    signedUrl: string;
    headers?: OutgoingHttpHeaders;
  }
  interface S3PutResponse {
    fileKey: string;
    // TODO: Add more here.
  }

  export type ReactS3UploaderOptions = ({
    files: File[]
  } | {
    fileElement: HTMLInputElement
  }) & {
    contentDisposition?: 'auto' | string;
    getSignedUrl?: (file: File, cb: (params: SignURLResponse) => void) => void;
    onError?: (message: string, file: File) => void;
    onFinishS3Put?: (result: S3PutResponse, file: File) => void;
    onProgress?: (percent: number, status: UploadStates, file: File) => void;
    onSignedUrl?: (response: SignURLResponse) => void;
    preprocess?: (file: File, next: (file: File) => void) => void;
    s3path?: string;
    scrubFilename?: (name: string) => string
    server?: string;
    signingUrl?: string;
    signingUrlHeaders?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
    signingUrlMethod?: 'GET' | 'POST';
    signingUrlQueryParams?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
    signingUrlWithCredentials?: boolean;
    uploadRequestHeaders?: OutgoingHttpHeaders;
  }

  export default class S3Upload {
    constructor(options: ReactS3UploaderOptions)
  }
}

Waiting to see if @seanadkinson is interested in merging here or else we should get this added to https://github.com/DefinitelyTyped/DefinitelyTyped/
We also need to add router types.

@Aror

Aror commented Jan 14, 2020

Copy link
Copy Markdown

Waiting for @seanadkinson to give update on this PR.

@seanadkinson

Copy link
Copy Markdown
Contributor

@Aror LGTM, will merge, thanks!

@seanadkinson seanadkinson merged commit 471ca1c into odysseyscience:master Jan 17, 2020
@seanadkinson

Copy link
Copy Markdown
Contributor

Released in 4.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants