I'm using typescript in relay and the props passed down is of type unknown. I have tried several ways to convince the compiler that it can have some property but it keeps showing me an error:
<QueryRenderer
environment={environment}
query={testQuery}
variables={{}}
render={({ error, props }) => {
if (error) {
return <div>Error!</div>;
}
if (!props) {
return <div>Loading...</div>;
}
if (!!props && _.isObject(props) && props.hasOwnProperty("Messages"))
return <MessageList messages={props.Messages} />;
}}
/>;
The above code doesn't work, typescript still warns me that
Property 'Messages' does not exist on type 'object'.
How to make this simple example work yet not make my code look hideous? Many thanks!