object is of type 'unknown'.ts(2571) code example

Example: typescript convert an unknown to string

// To convert an unknown type into any other type we can use assertions


let demo: unknown = 'Rice Krispies';
// The above line would throw an error as an unknown variable can 
// only take values of unknown and any type

let demo: unknown = 'The EXTRA cripsy colonel...' as string;

// the as string assertion allows us to set an unknown type to a string type
// This can be done with any other variable types it is not 
// limited to string