Comments (5)
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.
NgRx v17.1.1 is released today ✅
from platform.
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.
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.
@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)
- untracked for all methods? HOT 4
- @ngrx/signals: ability to save entity class instance on updateEntity() HOT 1
- Expose more models to the public API: SignalStoreFeatureResult and InputSignalStore<Input>
- Using a custom generic function for defining props in createActionGroup results in weird TypeScript errors HOT 4
- Chaining custom signal store features with input declared as functions fails HOT 2
- @ngrx/effects/src/effect_creator.d.ts:12:43 - error TS2313: Type parameter 'OT' has a circular constraint. HOT 17
- Schematics 'feature' gives error "Property 'entity' does not match the schema. 'false' should be a 'boolean'." HOT 8
- `patchState` TypeScript v5.4 compilation error HOT 3
- updater-explicit-return-type No longer needed with NoInfer HOT 2
- Cannot generate feature inside module with schematics HOT 2
- RFC: Allow constructor injection of SignalStore
- RFC: SignalStore with WritableSignals and ReadOnlySignalStore HOT 8
- Signal Store with Angular SSR initiate store in every injected component HOT 2
- Type 'Unsubscribable' must have a '[Symbol.iterator]()' method that returns an iterator. HOT 2
- Return type of selectQueryParam is incorrect HOT 2
- SignalStore Methods code snipped has probably a flaw HOT 4
- eslint plugin should use correct version of 'concatLatestFrom' in autofix for rule 'prefer-concat-latest-from' HOT 5
- Provide properly typed selectors example for CustomSerializer
- No usage notes for `tapResponse`, `concatLatestFrom` operators. HOT 1
- Ngrx dependency injection issue with esbuild/build-angular:application HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from platform.