Skip to content

Support of types keys for storage instance #815

@ipakhomov

Description

@ipakhomov

Hey there, thanks for amazing library!

Currently, keys for values in a storage aren't typed, they are just strings.

Having ability to pass an optional generic type when initializing a new mmkv instance could improve developer experience.
This will allow to specify which values are usable with particular storage instance. Example:

type StorableValues = 'token' | 'userId';

export const storage = new MMKV<StorableValues>({ ... });
...
storage.getString('foo'); // Typescript will report this error
storage.getString('token'); // All good

Of course, this can be achieved using a separate enum for keys in the app, but having generic support is more elegant and easier in use.

Please let me know if this feature is desirable, and you'd like me to submit a PR with these changes!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions