Skip to content

Offer types for getters on the Store instance #1843

@rich-w-lee

Description

@rich-w-lee

What problem does this feature solve?

The getters key of the Store instance has type any which is not useful. While type casting can be used, it's just a pain to have to do every single place you would want to reference a getter.

What does the proposed API look like?

One solution would be to offer a second (optional) generic type of the Store type that would default to any, and have that value be used for the type of the getters key.

export declare class Store<S, G = any> {
  constructor(options: StoreOptions<S>);

  readonly state: S;
  readonly getters: G;

  ...
}

I've tested the above solution and it works and should also be backwards compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions