我使用 Immutable.js 和 TypeScript 来构建 Redux 应用程序。
本质上,我的州看起来像
const defaultState = {
booleanValue: true,
numberValue: 0,
}
const StateRecord = Immutable.Record(defaultState)
class StateClass extends StateRecord {
booleanValue: boolean
numberValue: number
}
const STATE = new StateClass()
(此设置启用对诸如 STATE.booleanValue === 'hi'
之类的表达式的编译时类型检查)
是否有任何方法可以启用 set
的编译时类型检查,例如 STATE.set('booleanValue', 'hi')
? (我希望编译器发出警告,指出 'booleanValue' 无法设置为 'hi'
。)
或者,是否有替代设置可以使 Immutable.js 和 TypeScript 在获取和设置时一起工作?
最佳答案
is there alternative setup to make Immutable.js and TypeScript work together both when getting and setting
如果没有将 StateRecord
包装在辅助函数中(基本上是向其抛出更多需要复制并保持同步的代码)。简而言之,不。
关于javascript - 使用 TypeScript 检查 Immutable.js Record.set 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37426610/