string not assignable to type Social
michaelpomogajko opened this issue · comments
Steps to reproduce
Share.shareSingle({
social: Share.Social.INSTAGRAM_STORIES,
stickerImage: url,
backgroundTopColor: '#000',
backgroundBottomColor: '#000',
appId: Constants.expoConfig?.extra?.fbAppId,
});
Expected behavior
No ts issue
Actual behavior
TS is creaming at me with the following error
Type 'string' is not assignable to type 'Social'.ts(2322)
types.d.ts(66, 5): The expected type comes from property 'social' which is declared here on type 'ShareSingleOptions'
Environment
- React Native version: 0.72.6
- Typescript version (if using typescript): 5.1.3
react-native-share
Version: master
this is in 10.0.2. The typescript types does not seem to be properly used.
As a work around, cast it to what is needed:
import { Social } from 'react-native-share';
Share.shareSingle({
social: Share.Social.INSTAGRAM_STORIES as Social.InstagramStories ,
stickerImage: url,
backgroundTopColor: '#000',
backgroundBottomColor: '#000',
appId: Constants.expoConfig?.extra?.fbAppId,
});
Problem Description
social
expects something of type Social
which is an enum.
Though what is exposed is:
INSTAGRAM_STORIES: NativeRNShare.getConstants().INSTAGRAMSTORIES || Social.InstagramStories,
which is indeed string || Social
possible solution
Perhaps casting it at the right place might do the trick (untested).
(NativeRNShare.getConstants().INSTAGRAMSTORIES || Social.InstagramStories) as Social.InstagramStories
``
@estani
You can use that enum Social.InstagramStories as value:
import Share, { Social } from 'react-native-share';
and use it like that:
social: Social.InstagramStories,
"react-native-share": "^10.0.2",
@LukasMod indeed, but I tried to state in my post that by doing so, you are not honouring the implemented behaviour:
NativeRNShare.getConstants().INSTAGRAMSTORIES || Social.InstagramStories
Not sure what NativeRNShare.getConstants().INSTAGRAMSTORIES
is used for, but I guess the idea would be, that a platform version might define different values, so it's better to use them... I guess...
In any case, they did it for a reason, so the work around, as you proposed, might have undesirable effects in certain platforms or versions thereof (current or in the future).
My 2c, anyways.
Thanks for your comments!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open