Skip to content

Commit 83304e1

Browse files
authored
refactor: remove useless generics (#722)
1 parent 9118ca0 commit 83304e1

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

src/fileTypes.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ const extensions = Object.freeze({
5353
zip: '.zip .gz',
5454
} as const)
5555

56-
export type PlatformTypes = {
57-
android: typeof mimeTypes
58-
ios: typeof utis
59-
windows: typeof extensions
60-
}
61-
export type SupportedPlatforms = 'ios' | 'android' | 'windows'
56+
export type PlatformTypes = typeof mimeTypes | typeof utis | typeof extensions
6257

6358
export const perPlatformTypes = {
6459
android: mimeTypes,

src/index.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Platform, ModalPropsIOS } from 'react-native'
22
import invariant from 'invariant'
3-
import type { PlatformTypes, SupportedPlatforms } from './fileTypes'
3+
import type { PlatformTypes } from './fileTypes'
44
import { perPlatformTypes } from './fileTypes'
55
import { NativeDocumentPicker } from './NativeDocumentPicker'
66

@@ -21,19 +21,16 @@ export type DirectoryPickerResponse = {
2121

2222
export type TransitionStyle = 'coverVertical' | 'flipHorizontal' | 'crossDissolve' | 'partialCurl'
2323

24-
export type DocumentPickerOptions<OS extends SupportedPlatforms> = {
25-
type?:
26-
| string
27-
| PlatformTypes[OS][keyof PlatformTypes[OS]]
28-
| Array<PlatformTypes[OS][keyof PlatformTypes[OS]] | string>
24+
export type DocumentPickerOptions = {
25+
type?: string | Array<PlatformTypes | string>
2926
mode?: 'import' | 'open'
3027
copyTo?: 'cachesDirectory' | 'documentDirectory'
3128
allowMultiSelection?: boolean
3229
transitionStyle?: TransitionStyle
3330
} & Pick<ModalPropsIOS, 'presentationStyle'>
3431

35-
export async function pickDirectory<OS extends SupportedPlatforms>(
36-
params?: Pick<DocumentPickerOptions<OS>, 'presentationStyle' | 'transitionStyle'>,
32+
export async function pickDirectory(
33+
params?: Pick<DocumentPickerOptions, 'presentationStyle' | 'transitionStyle'>,
3734
): Promise<DirectoryPickerResponse | null> {
3835
if (Platform.OS === 'ios') {
3936
const result = await pick({
@@ -48,27 +45,23 @@ export async function pickDirectory<OS extends SupportedPlatforms>(
4845
}
4946
}
5047

51-
export function pickSingle<OS extends SupportedPlatforms>(
52-
opts?: DocumentPickerOptions<OS>,
53-
): Promise<DocumentPickerResponse> {
48+
export function pickSingle(opts?: DocumentPickerOptions): Promise<DocumentPickerResponse> {
5449
const options = {
5550
...opts,
5651
allowMultiSelection: false,
5752
}
5853
return pick(options).then((results) => results[0])
5954
}
6055

61-
export function pick<OS extends SupportedPlatforms>(
62-
opts?: DocumentPickerOptions<OS>,
63-
): Promise<DocumentPickerResponse[]> {
56+
export function pick(opts?: DocumentPickerOptions): Promise<DocumentPickerResponse[]> {
6457
const options = {
6558
// must be false to maintain old (v5) behavior
6659
allowMultiSelection: false,
6760
type: [types.allFiles],
6861
...opts,
6962
}
7063

71-
const newOpts: DoPickParams<OS> = {
64+
const newOpts: DoPickParams = {
7265
presentationStyle: 'formSheet',
7366
transitionStyle: 'coverVertical',
7467
...options,
@@ -78,16 +71,14 @@ export function pick<OS extends SupportedPlatforms>(
7871
return doPick(newOpts)
7972
}
8073

81-
type DoPickParams<OS extends SupportedPlatforms> = DocumentPickerOptions<OS> & {
82-
type: Array<PlatformTypes[OS][keyof PlatformTypes[OS]] | string>
74+
type DoPickParams = DocumentPickerOptions & {
75+
type: Array<PlatformTypes | string>
8376
allowMultiSelection: boolean
8477
presentationStyle: NonNullable<ModalPropsIOS['presentationStyle']>
8578
transitionStyle: TransitionStyle
8679
}
8780

88-
function doPick<OS extends SupportedPlatforms>(
89-
options: DoPickParams<OS>,
90-
): Promise<DocumentPickerResponse[]> {
81+
function doPick(options: DoPickParams): Promise<DocumentPickerResponse[]> {
9182
invariant(
9283
!('filetype' in options),
9384
'A `filetype` option was passed to DocumentPicker.pick, the correct option is `type`',

0 commit comments

Comments
 (0)