error TS2571: Object is of type ‘unknown’.
Bad Code ❌
If you use third-party libraries then it can happen that TypeScript cannot infer all return types. In such a case a return type can be
unknown which makes it impossible to access its properties from TypeScript. In the following example such case is constructed by assigning
unknown to an exemplary constant:
Fixed Code ✔️
To solve the problem of accessing properties from an unknown object, we have to define the type of the object which we want to access: