在使用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'
}
}
);
// AOT purposes
export function reducer(state: ISampleState | undefined, action: Action): ISampleState {
return sampleReducer(state, action);
}
Run Code Online (Sandbox Code Playgroud)
在实际运行代码后,我会看到DevToolsstore 确实填充了这个无根据的属性。
我最大的担忧是当我在return块内的减速器中有一个错字时,它也不会抱怨。
即如果我不小心打字
return {
...state,
Id: id //should be `id`
}
Run Code Online (Sandbox Code Playgroud)
很难找到错误,因为它编译得很好,没有抱怨。
有任何想法吗?
| 归档时间: |
|
| 查看次数: |
919 次 |
| 最近记录: |