Skip to content

export Objectish type #1041

@macmillen

Description

@macmillen

🚀 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);
    },
  };

  // ...
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions