TypeScriptの新しいts-checkを使用して、ジェネリック関数の処理方法を理解できません。Typescript ts-check javascript generics
/**
* @type {Reducer<IPoiState, any>}
*/
const poi = handleActions({
[ADD_BOOKMARK_START]: (state) => {
return { ...state };
},
}, {});
handleActionsタイプはDefinitey型付きから来ているので、
export function handleActions<State>(
reducerMap: ReducerMap<State>,
initialState: State
): Reducer<State, any>;
...のように見える、私は
Type 'Reducer<{}, any>' is not assignable to type 'Reducer<IPoiState, any>'.
Type '{}' is not assignable to type 'IPoiState'.
がとにかくそこには...というエラーを取得していますジェネリックを強制する?
「IPoiState」はどのように見えるのですか? –
私は推測することができますが、あなたの 'handleActions'宣言から出てくる型が間違っていると思います。 'State'と' IPoiState'は型システムのどこかにありますか?型システムは 'handleActions'が' Reducer <{}, any> 'を返すと間違って判断していますので、実際に' Reducer 'の型にする必要があります(' State'は 'IPoiState ')。 TypeScriptに 'duck typing'があるので、 –