From 3dce4521054b25df0bbc0cbfb50d9e413ae6be50 Mon Sep 17 00:00:00 2001 From: tkow Date: Sun, 7 Jul 2019 23:57:38 +0900 Subject: [PATCH] enable check type file at vscode and recover latest type --- __tests__/typescript/index.test.ts | 11 +++++++ index.d.ts | 49 +++++++++++++++++++++++++----- tsconfig.json | 7 +++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 __tests__/typescript/index.test.ts create mode 100644 tsconfig.json diff --git a/__tests__/typescript/index.test.ts b/__tests__/typescript/index.test.ts new file mode 100644 index 0000000..4c4d1e3 --- /dev/null +++ b/__tests__/typescript/index.test.ts @@ -0,0 +1,11 @@ +import { DocumentPicker} from "react-native-document-picker"; + +DocumentPicker.types.allFiles +DocumentPicker.types.audio +DocumentPicker.types.images +DocumentPicker.types.plainText +DocumentPicker.types.video + +DocumentPicker.pick({ + type: [DocumentPicker.types.allFiles] +}) \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 220887b..c0cfa0c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,38 @@ declare module 'react-native-document-picker' { - interface DocumentPickerOptions { - filetype: Array; - multiple?: Boolean; + type Types = { + mimeTypes: { + allFiles: '*/*', + audio: 'audio/*', + images: 'image/*', + plainText: 'text/plain', + pdf: 'application/pdf', + video: 'video/*', + }, + utis: { + allFiles: 'public.content', + audio: 'public.audio', + images: 'public.image', + plainText: 'public.plain-text', + pdf: 'com.adobe.pdf', + video: 'public.movie', + }, + extensions: { + allFiles: '*', + audio: + '.3g2 .3gp .aac .adt .adts .aif .aifc .aiff .asf .au .m3u .m4a .m4b .mid .midi .mp2 .mp3 .mp4 .rmi .snd .wav .wax .wma', + images: '.jpeg .jpg .png', + plainText: '.txt', + pdf: '.pdf', + video: '.mp4', + }, + }; + type PlatformTypes = { + android: Types['mimeTypes'] + ios: Types['utis'] + windows: Types['extensions'] + }; + interface DocumentPickerOptions { + type: Array } interface DocumentPickerResponse { uri: string; @@ -9,12 +40,14 @@ declare module 'react-native-document-picker' { fileName: string; fileSize: string; } - export class DocumentPicker { - static pick( - options: { multiple: false } & DocumentPickerOptions + type Platform = 'ios' | 'android' | 'windows' + export class DocumentPicker { + static types: PlatformTypes['ios'] | PlatformTypes['android'] | PlatformTypes['windows'] + static pick( + options: DocumentPickerOptions ): Promise; - static pickMultiple( - options: { multiple: true } & DocumentPickerOptions + static pickMultiple( + options: DocumentPickerOptions ): Promise; static isCancel(err: any): void; } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0bb7bf6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "baseUrl": "./__tests__/typescript" , + "types": ["./","./node_modules"] + }, + "include": ["./"] +} \ No newline at end of file