Providing a data structure with vanilla objects and a JS stream is easy:
type ExampleObjType = {
key1: number,
key2: string
};
const obj: ExampleObjType = {
key1: 123,
key2: '123'
};
This seems to require an unnecessarily large number of templates to provide a similar structure in an immutable:
type TestSpec = {
key1: number,
key2: string,
};
const TestRecord = Record({
key1: 0,
key2: '',
});
const record: TestSpec & Record<TestSpec> = new TestRecord({
key1: 123,
key2: '123',
});
In addition, this structure has some basic disadvantages:
- Force Defaults
- Initialization does not force invalid keys, only on access
Ideally, I could use Immutable.Mapsomething like this:
type TestSpec = Map<{key1: number, key2: number}>;
const testMap: TestSpec = Map({
key1: 123,
key2: '123',
});
However, the current implementation allows only key type and values to be entered. I could restrict the type of key using something like hokey like type Key = 'key1' | 'key2', but I still don't need to explicitly enter values for the key.
, ? , , , Redux.