Skip to content

multiGet return type incorrect? #764

Closed
@mtt87

Description

@mtt87

What happened?

👋 while using the library I noticed that multiGet has this signature:

multiGet: (keys: string[], callback?: MultiGetCallback) => Promise<readonly KeyValuePair[] | void>;

I'm not sure the return type is correct

Promise<readonly KeyValuePair[] | void>

It seems like void doesn't make sense, if I understood correctly how it works when a value doesn't exist it will return [string null] so the KeyValuePair[] is always the return type, not sure in which scenario it would return void.

I noticed it because Typescript is not happy when doing this

const values = await AsyncStorage.multiGet([ KEY1, KEY2, KEY3 ]);
setSomething(values[0][1]);

Showing this type error

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'void | readonly KeyValuePair[]'.
  Property '0' does not exist on type 'void | readonly KeyValuePair[]'.

Version

1.16.1

What platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows
  • web

System Information

n/a

Steps to Reproduce

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions