我是打字稿的新手,在這里我一直在向我的專案中添加打字稿,但出現了這個奇怪的錯誤: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error. Argument of type '{ identifier: string; }' is not assignable to parameter of type 'ConcatArray<never>'. Type '{ identifier: string; }' is missing the following properties from type 'ConcatArray<never>': length, join, slice Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error. Argument of type '{ identifier: string; }' is not assignable to parameter of type 'ConcatArray<never>'.ts(2769)
我的代碼給我的是(reducers.ts):
interface Update_AnalyserState {
identifier: string;
}
const initialArticleState= {
analysers: [],
};
export function articleReducer(
state = initialArticleState,
action: articleReducerAction
) {
switch (action.type) {
case ActionType.UPDATE_ANALYSER:
return {
...state,
analysers: state.analysers
.filter(
(a: Update_AnalyserState) =>
a.identifier != action.payload.identifier
)
.concat(action.payload),
};
}
}
對此有任何幫助/建議嗎?
uj5u.com熱心網友回復:
從您的示例中除錯并不容易,但我認為問題在于
const initialSiteArticleState = {
analysers: [],
};
你的分析器是一個空陣列型別,所以這意味著它是never[]. 所以過濾器的結果將是一個never[]. 因此,您必須正確鍵入該initialSiteArticleState.
就像是
const initialSiteArticleState:{analysers: Update_AnalyserState[]} = {
analysers: [],
};
試一試。這也是我試圖重現您的代碼的游樂場。如果您將滑鼠懸停在上面,tmp您可以看到它的型別never[]。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/334960.html
標籤:javascript 反应 打字稿 反应钩子 redux-工具包
上一篇:標題和側邊欄之間的間距問題
