From f557f4970f4d16129645dd1529f6c78e18b8ef5a Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 30 May 2024 10:50:21 +0200 Subject: [PATCH] refactor: remove useless generics --- src/fileTypes.ts | 7 +------ src/index.tsx | 31 +++++++++++-------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/fileTypes.ts b/src/fileTypes.ts index f0b3e697..c99b4956 100644 --- a/src/fileTypes.ts +++ b/src/fileTypes.ts @@ -53,12 +53,7 @@ const extensions = Object.freeze({ zip: '.zip .gz', } as const) -export type PlatformTypes = { - android: typeof mimeTypes - ios: typeof utis - windows: typeof extensions -} -export type SupportedPlatforms = 'ios' | 'android' | 'windows' +export type PlatformTypes = typeof mimeTypes | typeof utis | typeof extensions export const perPlatformTypes = { android: mimeTypes, diff --git a/src/index.tsx b/src/index.tsx index 4a59ea01..c05182a4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,6 @@ import { Platform, ModalPropsIOS } from 'react-native' import invariant from 'invariant' -import type { PlatformTypes, SupportedPlatforms } from './fileTypes' +import type { PlatformTypes } from './fileTypes' import { perPlatformTypes } from './fileTypes' import { NativeDocumentPicker } from './NativeDocumentPicker' @@ -21,19 +21,16 @@ export type DirectoryPickerResponse = { export type TransitionStyle = 'coverVertical' | 'flipHorizontal' | 'crossDissolve' | 'partialCurl' -export type DocumentPickerOptions = { - type?: - | string - | PlatformTypes[OS][keyof PlatformTypes[OS]] - | Array +export type DocumentPickerOptions = { + type?: string | Array mode?: 'import' | 'open' copyTo?: 'cachesDirectory' | 'documentDirectory' allowMultiSelection?: boolean transitionStyle?: TransitionStyle } & Pick -export async function pickDirectory( - params?: Pick, 'presentationStyle' | 'transitionStyle'>, +export async function pickDirectory( + params?: Pick, ): Promise { if (Platform.OS === 'ios') { const result = await pick({ @@ -48,9 +45,7 @@ export async function pickDirectory( } } -export function pickSingle( - opts?: DocumentPickerOptions, -): Promise { +export function pickSingle(opts?: DocumentPickerOptions): Promise { const options = { ...opts, allowMultiSelection: false, @@ -58,9 +53,7 @@ export function pickSingle( return pick(options).then((results) => results[0]) } -export function pick( - opts?: DocumentPickerOptions, -): Promise { +export function pick(opts?: DocumentPickerOptions): Promise { const options = { // must be false to maintain old (v5) behavior allowMultiSelection: false, @@ -68,7 +61,7 @@ export function pick( ...opts, } - const newOpts: DoPickParams = { + const newOpts: DoPickParams = { presentationStyle: 'formSheet', transitionStyle: 'coverVertical', ...options, @@ -78,16 +71,14 @@ export function pick( return doPick(newOpts) } -type DoPickParams = DocumentPickerOptions & { - type: Array +type DoPickParams = DocumentPickerOptions & { + type: Array allowMultiSelection: boolean presentationStyle: NonNullable transitionStyle: TransitionStyle } -function doPick( - options: DoPickParams, -): Promise { +function doPick(options: DoPickParams): Promise { invariant( !('filetype' in options), 'A `filetype` option was passed to DocumentPicker.pick, the correct option is `type`',