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

export Objectish type #1041

Closed
macmillen opened this issue Apr 25, 2023 · 1 comment
Closed

export Objectish type #1041

macmillen opened this issue Apr 25, 2023 · 1 comment
Labels

Comments

@macmillen
Copy link
Contributor

🚀 Feature Proposal

I created a wrapper for immer in Svelte to enhance its capabilities and I am using a generic type for that. The problem is that applyPatches accepts a type that extends the Objectish type which I cannot import. I propose to export this type.

Can this be solved in user-land code?

I can copy paste the type from the source code.

Example

import { applyPatches, enablePatches } from "immer";

// I need to duplicate this because there is no export in immer
type Objectish = { [key: string]: unknown } | Array<unknown> | Set<unknown> | Map<unknown, unknown>;

enablePatches();

export const createImmerStore = <T extends Objectish>(obj: T) => {
  let state = obj;

  const draftStore = {
    // ...
    undo() {
      // if I don't use `T extends Objectish` it throws an error
      state = applyPatches(state, undo.inversePatches);
    },
  };

  // ...
};
@mweststrate
Copy link
Collaborator

mweststrate commented Apr 25, 2023 via email

This was referenced Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants