Typescript中解构赋值并取别名时如何再定义类型?

justable
  • 178
// Error: Binding element 'id' implicitly has an 'any' type
function next(state: { id: number }, { payload: id }) {
  state.id = id;
}
next({ id: 1 }, { payload: 2 });
回复
阅读 2.7k
1 个回答
function next(state: { id: number }, { payload: id }: { payload: number }) {
  state.id = id;
}
你知道吗?

宣传栏