Skip to content

Commit 3dce452

Browse files
committed
enable check type file at vscode and recover latest type
1 parent 850f8ba commit 3dce452

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

__tests__/typescript/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DocumentPicker} from "react-native-document-picker";
2+
3+
DocumentPicker.types.allFiles
4+
DocumentPicker.types.audio
5+
DocumentPicker.types.images
6+
DocumentPicker.types.plainText
7+
DocumentPicker.types.video
8+
9+
DocumentPicker.pick({
10+
type: [DocumentPicker.types.allFiles]
11+
})

index.d.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
11
declare module 'react-native-document-picker' {
2-
interface DocumentPickerOptions {
3-
filetype: Array<string>;
4-
multiple?: Boolean;
2+
type Types = {
3+
mimeTypes: {
4+
allFiles: '*/*',
5+
audio: 'audio/*',
6+
images: 'image/*',
7+
plainText: 'text/plain',
8+
pdf: 'application/pdf',
9+
video: 'video/*',
10+
},
11+
utis: {
12+
allFiles: 'public.content',
13+
audio: 'public.audio',
14+
images: 'public.image',
15+
plainText: 'public.plain-text',
16+
pdf: 'com.adobe.pdf',
17+
video: 'public.movie',
18+
},
19+
extensions: {
20+
allFiles: '*',
21+
audio:
22+
'.3g2 .3gp .aac .adt .adts .aif .aifc .aiff .asf .au .m3u .m4a .m4b .mid .midi .mp2 .mp3 .mp4 .rmi .snd .wav .wax .wma',
23+
images: '.jpeg .jpg .png',
24+
plainText: '.txt',
25+
pdf: '.pdf',
26+
video: '.mp4',
27+
},
28+
};
29+
type PlatformTypes = {
30+
android: Types['mimeTypes']
31+
ios: Types['utis']
32+
windows: Types['extensions']
33+
};
34+
interface DocumentPickerOptions<OS extends keyof PlatformTypes> {
35+
type: Array<PlatformTypes[OS][keyof PlatformTypes[OS]]>
536
}
637
interface DocumentPickerResponse {
738
uri: string;
839
type: string;
940
fileName: string;
1041
fileSize: string;
1142
}
12-
export class DocumentPicker {
13-
static pick(
14-
options: { multiple: false } & DocumentPickerOptions
43+
type Platform = 'ios' | 'android' | 'windows'
44+
export class DocumentPicker<OS extends keyof PlatformTypes = Platform> {
45+
static types: PlatformTypes['ios'] | PlatformTypes['android'] | PlatformTypes['windows']
46+
static pick<OS extends keyof PlatformTypes = Platform>(
47+
options: DocumentPickerOptions<OS>
1548
): Promise<DocumentPickerResponse>;
16-
static pickMultiple(
17-
options: { multiple: true } & DocumentPickerOptions
49+
static pickMultiple<OS extends keyof PlatformTypes = Platform>(
50+
options: DocumentPickerOptions<OS>
1851
): Promise<DocumentPickerResponse>;
1952
static isCancel(err: any): void;
2053
}

tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./__tests__/typescript" ,
4+
"types": ["./","./node_modules"]
5+
},
6+
"include": ["./"]
7+
}

0 commit comments

Comments
 (0)