Git Product home page Git Product logo

Comments (5)

markostanimirovic avatar markostanimirovic commented on June 2, 2024 2

It seems that SignalStore pushes the limits of TypeScript. 😅 I'll try to find a fix for this issue. In the meantime, you can use the following workaround:

function EntityFilter<T extends object>(properties: (keyof T)[]) {
  const initial = Object.fromEntries(
    properties.map(prop => [prop, null])
  ) as { [K in keyof T]: T[K] | null }

  const entityFilterMethods = withMethods(store => ({
    updateFilter<K extends keyof T>(property: K, value: T[K]){
      patchState(store, (state) => ({
        ...state,
        [property]: value
      }));
    }
  }));

  return signalStore(withState(initial), entityFilterMethods);
}

By moving withMethods outside of the signalStore chain, the updateFilter method type will be properly inferred.

from platform.

markostanimirovic avatar markostanimirovic commented on June 2, 2024 2

NgRx v17.1.1 is released today ✅

from platform.

SerkanSipahi avatar SerkanSipahi commented on June 2, 2024 1

I dont know when the next release (minor, patch) for NgRx is but there is an npm package patch lib which can patch 3rd party libs in node_modules https://dev.to/zhnedyalkow/the-easiest-way-to-patch-your-npm-package-4ece

BTW: many thanks to the NgRx team and especially to you. The SignalStore is incredibly powerful and extendable.

from platform.

SerkanSipahi avatar SerkanSipahi commented on June 2, 2024

@markostanimirovic

I would also like to join this discussion because our issue goes in the same direction but I am not sure it is a TypeScript or SignalStore limitation.

Minimal reproduction of the bug/regression with instructions:

I was trying to create a "generic" signalStoreFeature factory with generic state type and generic methods.

Example:

export const createWithRequest = <RestEndpoint Record<string, string>>(
  restEndpoints: RestEndpoint,
) => ({
  withRequest: signalStoreFeatureFactory(restEndpoints),
});

export function signalStoreFeatureFactory<RestEndpoint extends Record<string, string>>(
  restEndpoints: RestEndpoint,
) {
  return () =>
    signalStoreFeature(
      withMethods(store => ({
        request: <Method extends keyof RestEndpoint & string>(method: Method) => {
          patchState(store, ...);
        },
      })),
    );
}

Usage:

type RestEndpoints = {
  get: {
    'meetings': Meeting[] | null;
  };
};

const requestState: RestEndpoints = {
  get: {
    meetings: null,
  },
};

export const { withRequest } = createWithRequest(requestState);

export const SomeStore = signalStore(
  withRequest(),
  withMethods(store => ({
    foo() {
      store.request('getttt'); // it should fail but somehow it is `any` type
    },
  })),
);

from platform.

SerkanSipahi avatar SerkanSipahi commented on June 2, 2024

@markostanimirovic
it seems your fix in #4249 (export type MethodsDictionary = Record<string, Function>;) solved it 🎉

Its there any workaround in the meantime for it?

from platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.