Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: Cast an object to other type using. How? And instanceof or typeof?

Tags:

typescript

Cast an object to other type using Typescript. How? And instanceof or typeof?

like image 318
shivlal kumavat Avatar asked Feb 04 '23 03:02

shivlal kumavat


1 Answers

Something like this:

let object = myObject as string; // this way
let object = <string> myObject; // or this way

In addition, instanceof returns a boolean, typeof returns the instance type.

like image 100
Aboodz Avatar answered May 29 '23 12:05

Aboodz