传播运算符给打字稿带来问题
spread operator giving issue with typescript
我正在尝试为我的 react-typescript 应用程序实现一个 redux 存储。我的减速机有问题。在本机反应应用程序中,我做了以下
reminders = [...state, reminder(action)];
return reminders;
传播运算符工作得很好。并且新对象被不变地添加到数组中。
打字稿不会发生这种情况。(得到一个空对象而不是数组)我试过object.assign
return (<any>Object).assign({}, state, reminder(action));
这会替换当前对象,而不是将其添加到数组中,我不认为它是以不可变的方式进行的。
我尝试了 uisng immutable.js 并且减速器根本没有被调用。
return map([state,reminder(action)])
不知道哪里出了问题。同样在使用 objext.assign 之后,nextprops 和 currents 道具总是相同的。即使它在 shouldContainerUpdate() 方法中被更改
the spread operator works perfectly. and the new object is added to array immutably.
在 TypeScript 中使用完全相同的方法,它将完美运行:
reminders = [...state, reminder(action)];
return reminders;
为什么
因为 TypeScript 遵循与 JavaScript 相同的语义 JavaScript 语法
我正在尝试为我的 react-typescript 应用程序实现一个 redux 存储。我的减速机有问题。在本机反应应用程序中,我做了以下
reminders = [...state, reminder(action)];
return reminders;
传播运算符工作得很好。并且新对象被不变地添加到数组中。
打字稿不会发生这种情况。(得到一个空对象而不是数组)我试过object.assign
return (<any>Object).assign({}, state, reminder(action));
这会替换当前对象,而不是将其添加到数组中,我不认为它是以不可变的方式进行的。
我尝试了 uisng immutable.js 并且减速器根本没有被调用。
return map([state,reminder(action)])
不知道哪里出了问题。同样在使用 objext.assign 之后,nextprops 和 currents 道具总是相同的。即使它在 shouldContainerUpdate() 方法中被更改
the spread operator works perfectly. and the new object is added to array immutably.
在 TypeScript 中使用完全相同的方法,它将完美运行:
reminders = [...state, reminder(action)];
return reminders;
为什么
因为 TypeScript 遵循与 JavaScript 相同的语义 JavaScript 语法