I am dealing with a React component that has certain props that need to be serialized and stored, as well as a function contained within them.
- However, my storage utility does not support storing functions, and I do not have the requirement of storing them either. Hence, I wrote a function to create a copy of the props object without including the function component:
/**
* Removes functions from the components props, so that the props can be pouched
*/
strippedProps(): Object {
let strippedProps: Object = {};
Object.keys(this.props).forEach((key) => {
let prop: any = this.props[key];
if (typeof (prop) != 'function') {
strippedProps[key] = prop;
}
})
return strippedProps;
}
I am facing TypeScript errors, and it is confusing because the variable prop
has been explicitly defined as any
.
https://i.sstatic.net/oZO5p.png
Why is TypeScript showing dissatisfaction with the initial error message? How can I modify the code to satisfy the compiler while still achieving the goal of generating this dynamic object?