Skip to content

Missing type inference when calling store.subscribe with a selector #555

Closed
@akbr

Description

@akbr

Type inference breaks when using store.subscribe with a selector.

import createStore from "zustand/vanilla";

const store = createStore(() => ({
  hello: "world"
}));

store.subscribe((state) => {
  // 👍 state type is inferred here
  console.log(state.hello);
});

store.subscribe(
  (state) => {
    // 💥 state type "unknown" here
    console.log(state.hello);
  },
  ({ hello }) => ({ hello })
);

Here's a Codesandbox.

Is this a known limitation?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions