'{ 标识符类型的参数:字符串; }' 不可分配给 'ConcatArray<never>' 类型的参数
Argument of type '{ identifier: string; }' is not assignable to parameter of type 'ConcatArray<never>'
我是 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),
};
}
}
任何 help/suggestion 与此 ?
从你的示例中调试起来并不容易,但我认为问题在于此
const initialSiteArticleState = {
analysers: [],
};
您的分析器是一个空数组类型,所以这意味着它是 never[]
。所以过滤器的结果将是 never[]
。所以你必须正确输入 initialSiteArticleState
.
类似
const initialSiteArticleState:{analysers: Update_AnalyserState[]} = {
analysers: [],
};
试一试。这也是我试图重现您的代码的 playground。如果将鼠标悬停在 tmp
上,您可以看到它的类型 never[]
.
我是 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),
};
}
}
任何 help/suggestion 与此 ?
从你的示例中调试起来并不容易,但我认为问题在于此
const initialSiteArticleState = {
analysers: [],
};
您的分析器是一个空数组类型,所以这意味着它是 never[]
。所以过滤器的结果将是 never[]
。所以你必须正确输入 initialSiteArticleState
.
类似
const initialSiteArticleState:{analysers: Update_AnalyserState[]} = {
analysers: [],
};
试一试。这也是我试图重现您的代码的 playground。如果将鼠标悬停在 tmp
上,您可以看到它的类型 never[]
.