Skip to content

Support user-defined generic types for useSharedState and usePicker #20

@karandeepsingh7070

Description

@karandeepsingh7070

Description

Currently, when using useSharedState and usePicker, the inferred types are limited, and developers need to explicitly specify the generic type even if the shared state is already typed. This adds unnecessary boilerplate for developers and makes the DX less clean.

Example:

const [user, setUser] = useSharedState<User>('user');
// or
const userName = usePicker<User, string>('user', user => user.name);

Ideally, the type should be inferred from the store itself so users do not have to re-specify the type repeatedly.


Proposal

  • Allow useSharedState and usePicker to automatically infer types from the registered shared state key.
  • Support optional user-defined generic override if needed, but keep it ergonomic for most use cases.

Benefits

✅ Reduces boilerplate for consumers
✅ Improves DX and type-safety without redundancy
✅ Makes Overwatch APIs feel more modern and aligned with TypeScript best practices


Tasks

  • Refactor useSharedState to infer type based on the key
  • Refactor usePicker to infer state type based on the key
  • Update documentation examples to showcase cleaner usage

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions