From da2e09f603ab4eb76fa7e56464b8e8aee0610bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Mon, 22 Oct 2018 17:47:20 +0200 Subject: [PATCH] [react-native-share] Syncing with flow types from repo (#29736) The types `Options` and `MultiOptions` as well as `OpenReturn` and `ShareSingleReturn` are taken directly from https://github.com/react-native-community/react-native-share/blob/7535726eb42205260c09d9f0a2b39ba6d00ebc2c/index.js and have only have been transformed to interfaces. The signature of the `shareSingle` call is missing `social` in the official repo as well, but from the native code it becomes apearent that it is required: https://github.com/react-native-community/react-native-share/blob/7535726eb42205260c09d9f0a2b39ba6d00ebc2c/ios/RNShare.m#L85-L122 --- types/react-native-share/index.d.ts | 49 ++++++++++++++----- .../react-native-share-tests.ts | 17 +++++-- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/types/react-native-share/index.d.ts b/types/react-native-share/index.d.ts index d407d4df96..bf382a8b2c 100644 --- a/types/react-native-share/index.d.ts +++ b/types/react-native-share/index.d.ts @@ -1,32 +1,55 @@ -// Type definitions for react-native-share 1.0 +// Type definitions for react-native-share 1.1 // Project: https://github.com/react-native-community/react-native-share#readme // Definitions by: Mark Nelissen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 declare namespace Share { - function open(options: OpenOptions): Promise; - function shareSingle(options: ShareSingleOptions): Promise; + function open(options: Options | MultipleOptions): Promise; + function shareSingle( + options: Options & { social: SupportedSocialApps } + ): Promise; } export default Share; -interface OpenOptions { - url: string; - type?: string; +interface OpenReturn { + app?: string; + dismissedAction?: boolean; +} + +interface ShareSingleReturn { message: string; +} + +interface Options { + url: string; + urls?: string[]; + type?: string; + message?: string; title?: string; subject?: string; excludedActivityTypes?: string; - showAppsToview?: boolean; + failOnCancel?: boolean; + showAppsToView?: boolean; } - -interface ShareSingleOptions { - url: string; +interface MultipleOptions { + url?: string; + urls: string[]; type?: string; - message: string; + message?: string; title?: string; subject?: string; - social: SupportedSocialApps; + excludedActivityTypes?: string; + failOnCancel?: boolean; + showAppsToView?: boolean; } -type SupportedSocialApps = 'twitter' | 'facebook' | 'whatsapp' | 'googleplus' | 'email'; +type SupportedSocialApps = + | "facebook" + | "pagesmanager" + | "twitter" + | "whatsapp" + | "instagram" + | "googleplus" + | "email"; diff --git a/types/react-native-share/react-native-share-tests.ts b/types/react-native-share/react-native-share-tests.ts index 375a4af4b6..a5702a9b59 100644 --- a/types/react-native-share/react-native-share-tests.ts +++ b/types/react-native-share/react-native-share-tests.ts @@ -1,12 +1,19 @@ import Share from 'react-native-share'; -// $ExpectType Promise +// $ExpectType Promise Share.open({ url: '', message: '', }); -// $ExpectType Promise +// $ExpectType Promise +Share.open({ + title: '', + message: '', + urls: [], +}); + +// $ExpectType Promise Share.open({ url: '', type: '', @@ -14,17 +21,17 @@ Share.open({ title: '', subject: '', excludedActivityTypes: '', - showAppsToview: true, + showAppsToView: true, }); -// $ExpectType Promise +// $ExpectType Promise Share.shareSingle({ url: '', message: '', social: 'facebook', }); -// $ExpectType Promise +// $ExpectType Promise Share.shareSingle({ url: '', type: '',