You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
myAdapter.getInitialState({
loaded: false,
searchText: '',
unkownProperty: "test" <--- This does NOT throw an error as I expect (since it is not a part of ExampleEntity)
})
as recommended in the documentation, unfortunately it is possible to introduce unknown properties without any error, such as the "unkownProperty" shown above.
To resolve this, I have type casted typing of getInitialState:
export const initialState: State = myAdapter.getInitialState<Omit<State, keyof EntityState<ExampleEntity>>>({
loaded: false,
searchText: '',
unkownProperty: "test" <--- This will now throw an error
});
If you have the time, perhaps you could introduce some more strict typing similar to the above to allow for IDE's to catch these sorts of errors without casting? Thanks very much for your time.
Describe any alternatives/workarounds you're currently using
export const initialState: State = myAdapter.getInitialState<Omit<State, keyof EntityState<ExampleEntity>>>({
loaded: false,
searchText: '',
unkownProperty: "test" <--- This will now throw an error
});
Using TypeScript's "Omit" as shown above allows for this to work.
I would be willing to submit a PR to fix this issue
Yes
No
The text was updated successfully, but these errors were encountered:
Which @ngrx/* package(s) are relevant/related to the feature request?
entity
Information
Hi NGRX Team,
When using NGRX Entity package and setting the initial state, unfortunately it is possible to introduce unknown properties.
I'd like to show briefly how I am solving this and ask if it's possible for you to implement this somehow for all to enjoy? Thanks in advance:
Firstly, in my reducers, consider this simplified initial Entity State, with an irrelevant entity type of "ExampleEntity":
when calling
as recommended in the documentation, unfortunately it is possible to introduce unknown properties without any error, such as the "unkownProperty" shown above.
To resolve this, I have type casted typing of getInitialState:
If you have the time, perhaps you could introduce some more strict typing similar to the above to allow for IDE's to catch these sorts of errors without casting? Thanks very much for your time.
Describe any alternatives/workarounds you're currently using
Using TypeScript's "Omit" as shown above allows for this to work.
I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: