ammarahm-ed / react-native-actions-sheet

A Cross Platform(Android, iOS & Web) ActionSheet with a flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.
https://rnas.vercel.app
MIT License
1.49k stars 121 forks source link

Type: .hide payload to match .show. How? #265

Closed luiscrjunior closed 1 year ago

luiscrjunior commented 1 year ago

Hello!

First of all, congratulations, really nice job!

But I have a question: how do I properly annotate the .hide return payload, to match the .show type?

For instance:

// types.ts

type MyType = {
   id: string;
   name: string;
}
// MyActionSheet.tsx

<Button
  onPress={() => {
    SheetManager.hide<MyType>(props.sheetId, {
      payload: data, // <---- not annotated
    });
  }}
  label="Submit"
/>
// Anywhere.tsx

<Button
  onPress={async () => {
    const result = await SheetManager.show<SheetProps, MyType>('MyActionSheet');
    if (result /* result is properly annotaded with MyType */) {
      console.log('result: ', result.name);
    }
  }}
/>,

Am I doing something wrong?

BTW, in the sheetmanager.d.td, we have:

    hide<ReturnPayload extends any>(id: string, options?: {
        /**
         * Return some data to the caller on closing the Sheet.
         */
        payload?: unknown;
        /**
         * Provide `context` of the `SheetProvider` to hide the action sheet.
         */
        context?: string;
    }): Promise<ReturnPayload>;

Can`t we change

payload?: unknown;

to

payload?: ReturnPayload;

?

So we could annotate .hide return payload.

Or is there another way?

Thanks in advance

ammarahm-ed commented 1 year ago

Yes, we can I think.

luiscrjunior commented 1 year ago

May I submit a PR?

266