Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to alias Unstable_EffectOn type #802

Closed
no-stack-dub-sack opened this issue Dec 15, 2022 · 0 comments · Fixed by #803
Closed

Unable to alias Unstable_EffectOn type #802

no-stack-dub-sack opened this issue Dec 15, 2022 · 0 comments · Fixed by #803

Comments

@no-stack-dub-sack
Copy link
Collaborator

Similar to #634 and the issue described and fixed in #790, users of easy-peasy were unable to define their own aliases of the Action, Computed, and Thunk types. The same is true for Unstable_EffectOn, e.g.

type AppEffectOn<TModel extends object> = Unstable_EffectOn<
  TModel,
  StoreModel,
  Injections
>;

interface StoreModel {
  todos: TodosModel;
  rootData: number;
}

interface TodosModel {
  items: { id: number; text: string }[];
  foo: string;
  setFoo: Action<TodosModel, string>;
  onStateChanged: AppEffectOn<TodosModel>;
}

const todosModel: TodosModel = {
  // ...
  onStateChanged: unstable_effectOn(
    [
      (state) => state.items, // error! Property 'items' does not exist on type 'StateMapper<FilterActionTypes<{}>>'
      (state, storeState) => storeState.rootData, // error!
    ],
    (actions, change, helpers) => {
      actions.setFoo('bar'); // error! Property 'setFoo' does not exist on type 'Actions<{}>'
      helpers.dispatch.todos.setFoo('plop'); // error!
      helpers.getState().items[0].id + 2; // error!

      return () => console.log('dispose');
    },
  ),
};

Since the generic type params of the type are not actually used, TypeScript "forgets" them when the type is aliased. The fix should be straightforward which I can spin up a PR for shortly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant