在使用ngrx我未使用createAction()and 的以前版本时,
createReducer()如果我尝试添加任何不属于所提供的State.
我将应用程序升级到Angular 8,并且ngrx 8.3.0也在使用。现在似乎类型安全不再存在,尽管NGRX文档指出大部分类型推断将被实现。
someState.ts
export interface ISampleState {
id: number
}
Run Code Online (Sandbox Code Playgroud)
someAction.ts
export const request = createAction('[SAMPLE] Request', props<{id: number}>();
Run Code Online (Sandbox Code Playgroud)
someReducer.ts
const initialState: ISampleState = {
id: null
}
const sampleReducer = createReducer(
initialState,
on(SampleActions.request, (state, { id }) => {
return {
...state,
id,
// Below would previously complain since only `id` is defined in the `ISampleState`
thisShouldNormallyComplain: 'but it does not'
} …Run Code Online (Sandbox Code Playgroud)