When it comes to dealing with immutable data structures, Immutable provides the handy fromJs
function. However, I've been facing issues trying to integrate it smoothly with Typescript. Here's what I've got:
type SubData = {
field1: string;
}
type Data = {
field0: string;
subData: SubData[];
};
const arr: Data[] = [];
const list: List<Data> = fromJS(arr);
^^^--- compiler error
An error message is displayed stating:
Type 'List<Map<keyof Data, string | List<Map<"field1", string>>>>' is not assignable to type 'List<Data>'
I attempted to resolve this by using:
const list: List<Data> = fromJS<Data[]>(arr);
However, this approach did not provide a solution. Any suggestions on how to rectify this issue?