我是新的typescript,在这里我一直在添加typescript到我的项目,得到这个奇怪的错误: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),
};
}
}
有什么帮助/建议吗?
从您的示例中调试并不容易,但我认为问题在于
const initialSiteArticleState = {
analysers: [],
};
你的分析器是一个空数组类型,所以它意味着它是never[]
。所以滤波的结果是never[]
。因此,您必须正确地键入initialSiteArticleState
。
const initialSiteArticleState:{analysers: Update_AnalyserState[]} = {
analysers: [],
};
试试吧。这里也是一个游乐场,我试图重现你的代码。如果你把鼠标悬停在tmp
上,可以看到它的字体是never[]
。