I am trying to filter a Record<string, string> by key value using the following code:
let records = someFunctionThatReturnsRecord();
records = Object.keys(records).filter((key) => k.indexOf("something") > -1).reduce((curr, key) => { return Object.assign(curr, { [key] : records[key]})}, {});
But I'm getting this error when I try to compile the code:
Overload 1 of 2, '(o: {}): string[]', gave the following error.
Argument of type 'Record<string, string> | undefined' is not assignable to parameter of type '{}'.
Type 'undefined' is not assignable to type '{}'.
Overload 2 of 2, '(o: object): string[]', gave the following error.
Argument of type 'Record<string, string> | undefined' is not assignable to parameter of type 'object'.
Type 'undefined' is not assignable to type 'object'.
I'm not sure what to make of the error. I'm unable to find anything about the error on search. Could someone please point me in the right direction. I'm new to typescript, but not to javascript and programming in general.